HTML CSS Bootstrap JavaScript jQuery MySQL PHP Data Mining

CSS Fonts

CSS font properties define the look and feel of the text on your website. Choosing the right font is crucial for readability and establishing a strong visual brand identity.


Font Family

The font-family property specifies the font for an element. It should hold several font names as a "fallback" system, to ensure maximum compatibility between browsers/operating systems.

p {
    font-family: "Times New Roman", Times, serif;
}

h1 {
    font-family: Arial, Helvetica, sans-serif;
}

Generic Font Families

Generic Family Description Example
Serif Fonts with small strokes at the edges. Times New Roman
Sans-serif Fonts without strokes (clean/modern). Arial / Helvetica
Monospace All characters have the same width. Courier New

Font Size

The font-size property sets the size of the text. You can use absolute or relative units.

h1 { font-size: 40px; }
h2 { font-size: 2.5rem; }
p { font-size: 100%; }
Tip: Always use **rem** or **em** for font-sizes to allow users to resize text in their browser settings for accessibility.

Font Style & Weight

Control the slant and thickness of your text.

1. Font Style

Mostly used to specify italic text.

p.normal { font-style: normal; }
p.italic { font-style: italic; }

2. Font Weight

Specifies the weight (boldness) of a font.

p.thick { font-weight: bold; }
p.custom { font-weight: 900; } /* Heavy black weight */

Font Shorthand

To shorten the code, you can use the font property to set multiple values at once.

/* font: style weight size/line-height family */
p {
    font: italic bold 20px/1.5 "Inter", sans-serif;
}

Using Google Fonts

If you don't want to use standard web-safe fonts, you can use Google Fonts. Just link the font in the <head> and use it in your CSS.

<!-- In HTML Head -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Outfit">

/* In CSS */
body {
    font-family: 'Outfit', sans-serif;
}