Dev.to WebDev 🛠 Dev 👁 0 📖 8 min read

Headline font vs body font: x-height and letter spacing

The short version Pick body fonts with a tall x-height and loose built-in letter spacing, because body text is small. Headline fonts can have a shorter x-height and tighter spacing. The x-height is the height of a low

The short version

  • Pick body fonts with a tall x-height and loose built-in letter spacing, because body text is small. Headline fonts can have a shorter x-height and tighter spacing.
  • The x-height is the height of a lowercase x. At 48px it measures 22.5px in Jost and 25.5px in Montserrat, even though both fonts have the same cap height.
  • Every font has letter spacing built in. At 48px, "Some text" is 196px wide in Jost and 244px in Montserrat, from wider letters and about 41% more space around each one.
  • You can measure any loaded font in the browser console: canvas measureText() gives the x-height from a lowercase x and the built-in spacing from each letter's advance width minus its ink.
  • Keep display fonts on large headlines. With a serif display font like Playfair Display the thin strokes give it away: about a third of a pixel thick at 16px.

A body font should have a tall x-height and loose built-in letter spacing, because body text is small and both of those make small letters easier to read. A headline font can get away with a shorter x-height and tighter spacing, since text at 48px is easy to read in almost anything.

Below I measure both properties on Jost (a headline font) and Montserrat (a body font), the pair I compare in the video above, then give the same numbers for a few popular Google Fonts, a snippet that measures any font for you, and where display fonts fit in.

Why headline fonts don't work as body text

Headline fonts are designed to look great on large text, and the things that make them look good at 48px make them harder to read at 16px. Body text is small and headlines are large. If you take a font that was drawn for headlines and set your paragraphs in it, you lose readability, and paragraphs are the part people actually have to read.

So the rule is simple: pick the right font for the job. When I'm choosing between a headline font and a body font, I only look at two things: the x-height and the letter spacing.

X-height: how tall the lowercase letters are

The x-height is the height of a lowercase x, measured from the baseline to its top. Most lowercase letters (a, c, e, m, n, o and so on) are about that tall, so it decides how big your lowercase text looks at any font size.

Set Jost and Montserrat side by side at 48px and weight 400 and the x in Montserrat is clearly bigger. I measured it in Chromium: the x is 22.5px tall in Jost and 25.5px in Montserrat, about 13% taller. Both fonts have the same cap height (0.704 of the font size, about 33.8px at 48px), so their capitals are the same height. All of the difference is in the lowercase, and body text is almost all lowercase.

At 16px that's 7.5px for Jost against 8.5px for Montserrat. One pixel doesn't sound like much, but at that size it's about 13% of the letter.

That's why body fonts get a taller x-height: small text needs all the help it can get. Headlines are already big, so readability isn't the problem there, and a font with a shorter x-height like Jost looks better at that size.

Inter's own description on Google Fonts says the same thing: it "features a tall x-height to aid in readability of mixed-case and lower-case text".

Letter spacing: the spacing built into the font

You can change letter spacing yourself with the letter-spacing property in CSS, or the same setting in Figma. But every font also has its own spacing baked in: each letter is drawn with a bit of empty space on either side of it, and that space is part of the font file.

Line up the two fonts again and the Jost text is a lot tighter, with the letters packed closer together, while the same words in Montserrat take up much more room. At 48px, "Some text" is 196px wide in Jost and 244px wide in Montserrat, 24% wider.

When I measured where that extra width comes from, it was both. The empty space around each lowercase letter averages 0.063em in Jost and 0.089em in Montserrat (41% more), and the letters themselves are about 20% wider in Montserrat too.

Wider spacing helps small text, because the letters don't run into each other and each word is easier to make out. Large headlines don't need that, and tighter spacing usually looks better on them, with the letters pulled closer together.

Jost vs Montserrat

Here's all of it in one place. Everything is measured in Chromium at weight 400.

Jost Montserrat
Use it for Headlines Body text
X-height 0.469em 0.532em
X-height at 48px 22.5px 25.5px
X-height at 16px 7.5px 8.5px
Space around each letter 0.063em 0.089em
"Some text" at 48px 196px wide 244px wide

So for headlines you want a shorter x-height and tighter letter spacing. For body text you want a taller x-height and wider letter spacing.

How popular Google Fonts compare

I ran the same measurements on a few fonts you've probably used, all at weight 400:

Font X-height X-height at 16px Space around each letter "Some text" at 48px
Jost 0.469em 7.5px 0.063em 196px
Lato 0.516em 8.3px 0.064em 210px
Montserrat 0.532em 8.5px 0.089em 244px
Roboto 0.532em 8.5px 0.075em 216px
Open Sans 0.547em 8.8px 0.079em 225px
Inter 0.547em 8.8px 0.086em 228px

Jost is the only one under 0.5em. The other five all sit between 0.516em and 0.547em. Lato's spacing is almost as tight as Jost's, but its x-height is clearly taller, so it still reads fine small. It's the short x-height and the tight spacing together that make Jost a headline font.

Measure any font yourself

You don't have to eyeball this. Paste the code below into the DevTools console on a page that already loads the fonts you want to compare, and change the names in the last loop:

async function fontMetrics(family, weight = 400) {
  const size = 1000; // measure big, because Chrome rounds the ink box to whole pixels
  const font = `${weight} ${size}px "${family}"`;
  const faces = await document.fonts.load(font);
  if (faces.length === 0) throw new Error(`${family} isn't loaded on this page`);

  const ctx = document.createElement("canvas").getContext("2d");
  ctx.font = font;

  // x-height: from the baseline to the top of a lowercase x
  const xHeight = ctx.measureText("x").actualBoundingBoxAscent / size;

  // Built-in spacing: each letter's advance width minus its ink, averaged over a-z
  let space = 0;
  for (const letter of "abcdefghijklmnopqrstuvwxyz") {
    const m = ctx.measureText(letter);
    space += m.width - m.actualBoundingBoxLeft - m.actualBoundingBoxRight;
  }

  return {
    family,
    xHeight: +xHeight.toFixed(3),
    spacing: +(space / 26 / size).toFixed(3),
  };
}

for (const family of ["Jost", "Montserrat"]) {
  const { xHeight, spacing } = await fontMetrics(family);
  console.log(`${family}: x-height ${xHeight} em, spacing ${spacing} em`);
}

It draws text on a canvas and reads two numbers from measureText(). actualBoundingBoxAscent for the letter x is the x-height. For the spacing, width is how far the letter moves the next one along, and the two bounding box values are where the ink actually is, so the difference is the empty space the font puts around the letter. Both are divided by the font size, so the results are in em and you can compare fonts at any size.

The measuring happens at 1000px because Chrome rounds the ink box to whole pixels. When I measured at 48px, Jost's x came out as 23px instead of 22.5px, and that kind of error swamps the gap in spacing, which is only a pixel or two per letter at that size. If the font isn't loaded on the page, document.fonts.load() finds nothing and the function throws instead of quietly measuring a fallback font.

On a page that loads Jost and Montserrat, it prints:

Jost: x-height 0.469 em, spacing 0.063 em
Montserrat: x-height 0.532 em, spacing 0.089 em

Display fonts: headlines only

This wouldn't be complete without display fonts. They're headline fonts taken further: they have striking, unusual shapes that look great on a big headline and make small text unreadable. Filter Google Fonts by the Display category and you'll see what I mean. At 120px most of them are fine. At 16px a lot of them are close to impossible to read.

So use a display font if you want your headlines to look like someone paid attention to the details, but keep it off your body text. A playful display font can look great on the headlines of a kids' website and still ruin the paragraphs underneath.

With serif fonts, x-height and spacing don't always give it away. Playfair Display is a display design (its Google Fonts description says so, and suggests Gelasio or Georgia for body text). When I measured it against Gelasio, Playfair's x-height was actually taller, 0.516em to 0.500em. The thin strokes give it away. I measured the top of the lowercase o: it's 0.020em thick in Playfair Display and 0.047em in Gelasio. At 16px that's a third of a pixel against three quarters of one, and a screen can only draw a third of a pixel as a faint grey line. So for serifs, look at how thin the thinnest strokes get as well.

A headline and body pairing in CSS

Here's Jost for headings and Montserrat for everything else, loaded from Google Fonts. Put this in your <head>:

<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Jost:wght@600&family=Montserrat:ital,wght@0,400;0,700;1,400&display=swap">

And this in your CSS:

body {
  font-family: "Montserrat", sans-serif;
  font-size: 1rem;
  line-height: 1.6;
}

h1,
h2,
h3 {
  font-family: "Jost", sans-serif;
  font-weight: 600;
  line-height: 1.1;
}

I load Montserrat's bold and italic styles too, so <strong> and <em> use real font files instead of the browser faking them. I go into why that matters in how I pick good fonts. I checked the result in Chromium at 1280px and 375px. The headings render in Jost SemiBold and the paragraphs in Montserrat, at both widths.

I don't add any letter-spacing here. These two fonts already have the spacing I want for each job, which is the whole point of picking them this way. Line height is the other setting that changes between headlines and body text, and I cover it in how to make your text readable for the web. For sizes and the rest of a type scale, see how to systemize your typography.

Don't overcomplicate it

These are basic rules, and that's fine. Body text gets a tall x-height and wider spacing, headlines get a shorter x-height and tighter spacing. Display fonts stay on headlines. If you just do that, you're already ahead of most designers.

If you want more of this, my book Designing Websites is everything I've learned building websites, and it's free.

Originally published on hassandev.me.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.