University of New Hampshire, Department of Computer Science

Information Technology 502
, Intermediate Web Design

Spring 2025

Jump to navigation

Design Template by Anonymous

Applying Typography in CSS

Now that we understand the foundations of typography, let’s look at how we bring type to life on the web using CSS. Cascading Style Sheets (CSS) is the language used to control visual presentation—including the way our text appears across different devices, browsers, and screen sizes. Good CSS typography isn’t just about looks; it also plays a major role in accessibility and user experience.

Using Web-Safe Fonts and Font Stacks

When choosing fonts, we often rely on web-safe fonts—typefaces that are pre-installed across most devices and operating systems. These include fonts like Arial, Verdana, Georgia, and Courier New. Using them ensures consistent rendering, but they offer limited personality.

To expand your design toolkit, CSS allows you to specify a font stack, listing fonts in order of preference. This way, if the first isn’t available, the browser will fall back to the next:

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

Always end with a generic family like serif or sans-serif to guarantee a backup.

Using Google Fonts and Custom Fonts

Thanks to services like Google Fonts, designers have access to a huge library of free, performance-optimized fonts. To use one, simply include a <link> in your HTML:

<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">

Then apply it in your CSS:

body {
       font-family: 'Roboto', sans-serif;
     }

Make sure to only load the weights and styles you need to avoid slowing down your site.

Key CSS Typography Properties

CSS gives us precise control over how text looks and behaves. Let’s break down the most essential properties for styling typography:

Relative vs. Absolute Units

Font size can be set using absolute units like px (pixels), or relative units like em, rem, and %.

For accessibility and responsive design, rem is often the best choice.

Responsive Typography

Typography needs to adapt to different screens and devices. Here’s how to make your text flexible and accessible:

body {
       font-size: 1rem;
     }
     
     @media (max-width: 600px) {
       body {
         font-size: 0.9rem;
       }
     }

Some designers also use fluid typography with clamp(), which lets font size adjust based on viewport width:

h1 {
       font-size: clamp(1.5rem, 4vw, 3rem);
     }

Responsive type ensures that your content stays readable and accessible no matter what device it's viewed on.