Skip to content

CSS Fonts

CSS Fonts control how text appears on web pages. Typography affects readability, accessibility, branding, user experience, and SEO. In this tutorial, you will learn font-family, font-size, font-weight, font-style, line-height, web fonts, Google Fonts, responsive typography, and font best practices.

What Are CSS Fonts?

CSS fonts define how text is displayed on a webpage. They control the typeface, size, weight, style, spacing, and readability of content.

body {
  font-family: Arial, sans-serif;
  font-size: 16px;
}

Every website uses fonts for headings, paragraphs, buttons, forms, navigation, and other content elements.

Why CSS Fonts Are Important

  • Improve content readability.
  • Strengthen branding and design consistency.
  • Support accessibility requirements.
  • Enhance user experience.
  • Help users scan content faster.
  • Support responsive web design.
  • Improve engagement and content consumption.

CSS Fonts Cheatsheet

Property Example Purpose
font-family font-family: Arial, sans-serif; Sets the font typeface.
font-size font-size: 1rem; Controls text size.
font-weight font-weight: 700; Controls thickness.
font-style font-style: italic; Makes text italic.
line-height line-height: 1.6; Controls line spacing.
letter-spacing letter-spacing: 1px; Controls character spacing.
word-spacing word-spacing: 4px; Controls spacing between words.
text-transform text-transform: uppercase; Changes letter casing.
font font: 400 1rem/1.5 Arial; Font shorthand property.

CSS font-family

The font-family property specifies which font should be used.

body {
  font-family: Arial, sans-serif;
}

h1 {
  font-family: Georgia, serif;
}

Always include fallback fonts in case the preferred font is unavailable.

Common Font Families

Family Example Fonts Common Use
Serif Georgia, Times New Roman Editorial and traditional content.
Sans-serif Arial, Helvetica, Inter Modern websites and applications.
Monospace Courier New, Consolas Code examples.
Cursive Comic Sans, Brush Script Decorative content.
Fantasy Various decorative fonts Special branding purposes.

CSS font-size

The font-size property controls the size of text.

body {
  font-size: 16px;
}

h1 {
  font-size: 2.5rem;
}

Common Units for Fonts

Unit Description Recommended
px Fixed size. Sometimes
rem Relative to root font size. Yes
em Relative to parent element. Yes
% Relative percentage size. Sometimes

CSS font-weight

Font weight controls text thickness.

h1 {
  font-weight: 700;
}

p {
  font-weight: 400;
}
Weight Description
100Thin
300Light
400Normal
500Medium
600Semi Bold
700Bold
800Extra Bold
900Black

CSS font-style

.quote {
  font-style: italic;
}

.normal {
  font-style: normal;
}

Italics are commonly used for quotes, citations, and emphasis.

CSS line-height

Line height controls vertical spacing between lines of text.

body {
  line-height: 1.6;
}

A line height between 1.5 and 1.8 is typically recommended for long-form content.

Letter and Word Spacing

h1 {
  letter-spacing: 1px;
}

p {
  word-spacing: 2px;
}

These properties improve readability and branding when used carefully.

Using Google Fonts

Google Fonts provides free web fonts that can be used on websites.

<link
  rel="preconnect"
  href="https://fonts.googleapis.com"
/>

<link
  href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap"
  rel="stylesheet"
/>
body {
  font-family: "Inter", sans-serif;
}

Popular Google Fonts include Inter, Roboto, Open Sans, Lato, Poppins, Montserrat, Nunito, and Merriweather.

Using Custom Web Fonts

@font-face {
  font-family: "MyFont";
  src: url("/fonts/myfont.woff2") format("woff2");
}

body {
  font-family: "MyFont", sans-serif;
}

Self-hosted fonts provide more control and can improve privacy and performance.

Responsive Typography

Font sizes should adapt to different screen sizes.

h1 {
  font-size: clamp(2rem, 5vw, 4rem);
}

The clamp() function creates fluid typography that scales smoothly between minimum and maximum values.

Popular Font Pairing Examples

Heading Font Body Font Style
Montserrat Open Sans Corporate
Poppins Inter Modern SaaS
Merriweather Roboto Blog & Editorial
Playfair Display Source Sans Pro Luxury Brand

CSS Fonts and Accessibility

  • Use readable font sizes.
  • Maintain adequate line height.
  • Avoid overly decorative fonts for body content.
  • Ensure sufficient color contrast.
  • Support browser zoom and text resizing.
  • Use responsive typography.
body {
  font-size: 1rem;
  line-height: 1.6;
}

CSS Fonts and SEO

Fonts do not directly affect search rankings, but typography impacts user experience, readability, accessibility, and engagement.

  • Readable text improves user engagement.
  • Accessible typography improves usability.
  • Optimized web fonts improve page speed.
  • Better reading experience can reduce bounce rates.

Common CSS Font Mistakes

  • Using too many font families.
  • Using tiny font sizes.
  • Ignoring line-height.
  • Loading unnecessary font weights.
  • Using decorative fonts for body text.
  • Not providing fallback fonts.
  • Using fixed pixel typography everywhere.

CSS Font Best Practices

  • Use 1–2 font families across a website.
  • Prefer modern web fonts such as Inter or Roboto.
  • Use rem units for scalable typography.
  • Use clamp() for responsive font sizing.
  • Keep body text readable.
  • Limit loaded font weights.
  • Use font-display: swap for performance.
  • Test typography on mobile devices.
  • Maintain adequate line-height.
  • Always include fallback fonts.

Key Takeaways

  • CSS fonts control how text appears on web pages.
  • font-family defines the typeface.
  • font-size controls text size.
  • font-weight controls thickness.
  • line-height improves readability.
  • Responsive typography improves user experience.
  • Good typography supports accessibility and SEO.

Pro Tip

For modern websites, a combination of Inter for body text, clamp() for responsive typography, and a line-height of 1.6 creates an excellent reading experience across devices.