Sub topic 8
Setting letter-spacing in CSS
This chapter assumes you know what kerning and tracking are, that tracking is measured in thousandths of an em, and that you can read basic CSS. Here you will apply tracking in the browser with letter-spacing.
What letter-spacing does
letter-spacing adds a fixed amount of space after every character in an element. It is the CSS version of tracking. It does not change pair kerning. The browser applies the font's kerning first, then adds your value on top.
A positive value opens the text. A negative value tightens it. The default, normal, adds nothing.
Use em, not px
You can write the value in px, rem, or em. For type, em is usually the best choice. An em is relative to the element's own font size, so the spacing scales when the size changes. This matches how design tools store tracking.
The conversion is a division by 1000. A tracking value of 75 in Figma or InDesign becomes 0.075em. A value of -20 becomes -0.02em.
function trackingToEm(units) {
return units / 1000;
}
console.log(trackingToEm(75) + 'em'); // "0.075em"
console.log(trackingToEm(-20) + 'em'); // "-0.02em"A fixed px value does not scale. If you set letter-spacing: -2px on a headline and later shrink the headline on mobile, the tightening becomes too strong.
A worked example
Large display text is often tightened slightly. Small all-caps labels are usually opened up.
.headline {
font-size: 4rem;
letter-spacing: -0.02em;
}
.eyebrow {
font-size: 0.75rem;
text-transform: uppercase;
letter-spacing: 0.12em;
}At 4rem (64px), -0.02em is about -1.3px per character. At 0.75rem (12px), 0.12em is about 1.4px per character. The same em logic produces different pixel amounts for each size.
Inheritance and computed values
letter-spacing is inherited, but what children inherit depends on the unit. If a parent sets letter-spacing: 0.1em, the browser computes that to an absolute length using the parent's font size. Children inherit that length, not the 0.1em ratio. A child with a larger font size will then not scale the spacing.
If a child has a different font size, set letter-spacing on the child directly.
Things to watch for
- Do not use
letter-spacingto fix one bad pair. It affects every character. Use kerning control for pair problems. - Avoid positive tracking on lowercase body text. It reduces readability and breaks the even texture of a paragraph.
- Non-zero
letter-spacingdisables optional ligatures in browsers. For tracked all-caps text, turn them off explicitly so the result is the same everywhere.
.tracked-caps {
text-transform: uppercase;
letter-spacing: 0.1em;
font-variant-ligatures: none;
}Quick reference
| Goal | Typical value | Notes |
|---|---|---|
| Large headline | -0.01em to -0.03em | Slight tightening |
| Body text | normal (0) | Leave it alone |
| Small all-caps label | 0.05em to 0.15em | Open for legibility |
| Convert from design tool | units / 1000 | Result is in em |
Exercise
A designer specifies a 48px heading with tracking of -25 in their design tool. Write the CSS declaration, and give the approximate spacing in pixels added after each character.
Show answer
Divide by 1000 to get -0.025em, so the declaration is letter-spacing: -0.025em;. At 48px, that is 48 × -0.025 = -1.2px per character, so each character is pulled about 1.2px closer to the next one.
Exercise
A parent sets letter-spacing: 0.1em at 16px. A child inside it has font-size: 32px and sets no letter-spacing. What spacing does the child use, and how would you make it scale with its own size?
Show answer
The child inherits the computed length of 1.6px (0.1 × 16px), not the ratio, so its spacing is 1.6px, which is only 0.05em at 32px. To make it scale, set letter-spacing: 0.1em on the child, which gives 3.2px.