
Font properties determine which typeface the browser uses and how it draws the text. A reliable font stack includes fallbacks so the page remains readable even when the preferred typeface is unavailable.
7. CSS font properties
7.1. Font family with font-family
List typefaces in order of preference. Quote names containing spaces and finish with an unquoted generic family such as serif, sans-serif, or monospace. The browser tries another family if a font is unavailable or lacks the character it needs.
font-family: "Open Sans", Arial, sans-serif;Open the corresponding example in CodePen
7.2. Font style with font-style
Use normal for upright text, italic for an italic face, or oblique for slanted text. A browser may synthesize the slant if the font does not supply the requested style.
font-style: italic;Open the corresponding example in CodePen
7.3. Font variant with font-variant
Small capitals display lowercase letters as smaller uppercase shapes. The quality depends on whether the typeface includes designed small capitals.
font-variant: small-caps;Open the corresponding example in CodePen
7.4. Font weight with font-weight
Normal corresponds to 400 and bold to 700. Numeric weights let you choose finer steps when the typeface supports them. Variable fonts can offer a range of weights. The browser matches the closest suitable face when a requested weight is missing.
font-weight: 600;Open the corresponding example in CodePen
7.5. Font size with font-size
Use keywords, lengths, or percentages. A percentage or em scales from the inherited font size when used on font-size. A rem scales from the root size, which is useful for a consistent type scale.
font-size: 1.25rem;Open the corresponding example in CodePen
Try it yourself
Set an article heading in a sans-serif font, give it a bold weight and make it 1.5 times the root font size.
Show one solution
article h2 {
font-family: Arial, sans-serif;
font-weight: 700;
font-size: 1.5rem;
}