Font Properties - Controlling Typeface & Style

What You'll Learn

  • Master font-family and build effective font stacks with fallbacks
  • Control text size with font-size using px, em, rem, and percentages
  • Adjust text thickness with font-weight from thin (100) to black (900)
  • Apply font-style for italic, oblique, and custom slant angles
  • Use font-variant for small caps and advanced capitalization
  • Adjust character width with font-stretch for condensed/expanded text
  • Control vertical spacing with line-height for optimal readability
  • Use the font shorthand to combine multiple properties efficiently
  • Follow accessibility best practices for font sizing and readability

Introduction to Font Properties

Font properties control the fundamental visual characteristics of text: the typeface used, its size, weight, style, and spacing. These properties form the foundation of typography on the web, affecting both aesthetics and readability.

While modern CSS offers many advanced typography features, mastering these core font properties is essential. They work universally across all browsers and provide the building blocks for more sophisticated text styling.

font-family - Choosing Typefaces

The font-family property specifies which typeface to use for text. Always provide multiple font options (a "font stack") with a generic family as the final fallback.

/* Font stack with fallbacks */ font-family: Georgia, 'Times New Roman', serif; /* System font stack (fast, native) */ font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; /* Monospace for code */ font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Courier New', monospace;

font-size - Controlling Text Size

The font-size property controls how large text appears. Use relative units for accessibility and maintainability.

/* Absolute units (not recommended) */ font-size: 16px; /* Fixed, doesn't scale with user settings */ /* Relative units (recommended) */ font-size: 1rem; /* Relative to root (usually 16px) */ font-size: 1.5em; /* Relative to parent font size */ font-size: 100%; /* Relative to parent (same as 1em) */ /* Practical examples */ body { font-size: 16px; } /* Base size */ h1 { font-size: 2.5rem; } /* 40px if root is 16px */ small { font-size: 0.875rem; } /* 14px if root is 16px */

font-weight - Text Thickness

The font-weight property controls how thick or bold text appears, ranging from 100 (thin) to 900 (black/heavy).

/* Numeric values (100-900) */ font-weight: 100; /* Thin */ font-weight: 300; /* Light */ font-weight: 400; /* Normal/Regular */ font-weight: 600; /* Semi-Bold */ font-weight: 700; /* Bold */ font-weight: 900; /* Black/Heavy */ /* Keyword values */ font-weight: normal; /* Same as 400 */ font-weight: bold; /* Same as 700 */ /* Relative values */ font-weight: lighter; /* One weight lighter than parent */ font-weight: bolder; /* One weight heavier than parent */

font-style - Italic and Oblique

The font-style property controls whether text appears upright (normal), slanted (italic/oblique), or at a custom angle.

/* Standard styles */ font-style: normal; /* Upright text */ font-style: italic; /* Cursive italic design */ font-style: oblique; /* Artificially slanted */ /* Oblique with custom angle */ font-style: oblique 10deg; /* 10-degree slant */ font-style: oblique 20deg; /* 20-degree slant */

font-variant - Small Caps & More

The font-variant property enables alternative glyphs, most commonly small capitals where lowercase letters appear as smaller uppercase letters.

/* Basic small caps */ font-variant: small-caps; /* Advanced capitalization variants */ font-variant-caps: small-caps; /* Lowercase as small caps */ font-variant-caps: all-small-caps; /* Everything as small caps */ font-variant-caps: petite-caps; /* Smaller small caps */ font-variant-caps: unicase; /* Mixed case heights */ font-variant-caps: titling-caps; /* Optimized for titles */ /* Numeric variants */ font-variant-numeric: oldstyle-nums; /* Old-style figures */ font-variant-numeric: tabular-nums; /* Fixed-width numbers */

font-stretch - Condensed & Expanded

The font-stretch property selects condensed or expanded versions of fonts, if available.

/* Keyword values */ font-stretch: ultra-condensed; /* 50% */ font-stretch: extra-condensed; /* 62.5% */ font-stretch: condensed; /* 75% */ font-stretch: semi-condensed; /* 87.5% */ font-stretch: normal; /* 100% */ font-stretch: semi-expanded; /* 112.5% */ font-stretch: expanded; /* 125% */ font-stretch: extra-expanded; /* 150% */ font-stretch: ultra-expanded; /* 200% */ /* Percentage values */ font-stretch: 75%; /* Condensed */ font-stretch: 125%; /* Expanded */

line-height - Vertical Spacing

The line-height property controls the vertical spacing between lines of text. It's crucial for readability.

/* Unitless (recommended - inherits as multiplier) */ line-height: 1; /* Tight, no extra space */ line-height: 1.5; /* Recommended for body text */ line-height: 2; /* Double spacing */ /* With units (not recommended - inherits as fixed value) */ line-height: 1.5em; /* Relative to font size */ line-height: 24px; /* Absolute */ line-height: 150%; /* Percentage */ /* Practical examples */ body { line-height: 1.6; /* Good for paragraphs */ } h1 { line-height: 1.2; /* Tighter for large headings */ } code { line-height: 1.4; /* Moderate for code blocks */ }

font Shorthand Property

The font shorthand combines multiple font properties into a single declaration. Order matters!

/* Full syntax */ font: [font-style] [font-variant] [font-weight] font-size[/line-height] font-family; /* Examples */ font: italic bold 1.2rem/1.8 Georgia, serif; /* Same as: */ font-style: italic; font-variant: normal; font-weight: bold; font-size: 1.2rem; line-height: 1.8; font-family: Georgia, serif; /* Minimal (size and family required) */ font: 16px Arial, sans-serif; /* With line-height */ font: 1rem/1.5 system-ui, sans-serif; /* All properties */ font: italic small-caps bold 1.25rem/1.6 'Helvetica Neue', sans-serif;

Key Takeaways

  • font-family: Always provide font stacks with fallbacks ending in a generic family
  • font-size: Use rem for accessibility - it scales with user browser settings
  • font-weight: Ranges from 100-900; 400 is normal, 700 is bold
  • font-style: Italic uses cursive design; oblique slants normal font
  • font-variant: Small caps are great for headings, acronyms, and elegant emphasis
  • font-stretch: Only works with fonts that include width variants
  • line-height: Use unitless values (1.5-1.6 recommended for body text)
  • font shorthand: Combines properties; size and family are required
  • System fonts (system-ui) load instantly - no network requests needed
  • Accessibility: relative units, adequate line spacing, sufficient contrast
  • Not all fonts support all weights, variants, or stretch values
  • Variable fonts offer continuous ranges for weight, width, and other properties