Sub topic 8
Setting letter-spacing in CSS
This chapter assumes you know the difference between kerning and tracking from earlier in the tutorial. It also assumes you can read basic CSS (selectors, properties, units). Here you will learn how letter-spacing behaves in the browser, how its values are computed and inherited, and where it surprises people.
What the property does
letter-spacing adds a fixed amount of space between adjacent characters, on top of whatever the font already provides. It is the CSS version of tracking in a design tool. The font's sidebearings and kerning pairs still apply. The property adds to them and does not replace them.
.example {
letter-spacing: normal; /* default: add nothing */
}The property accepts two kinds of value:
normaladds no extra space. The browser may still adjust spacing when text is justified.- A length such as
0.05em,1px, or0.1remis added after each character. Positive values loosen the text. Negative values tighten it.0is similar tonormalfor most purposes, butnormalis the only value that lets the browser adjust spacing for justification.
A first example
The spine's basic pairing is a tight headline and an open all-caps label:
.headline {
font-size: 4rem;
letter-spacing: -0.02em;
}
.eyebrow {
font-size: 0.75rem;
text-transform: uppercase;
letter-spacing: 0.12em;
}The headline is tightened by 2% of its font size. The eyebrow label is opened by 12% of its font size. Large display type usually looks too loose at default spacing, and small caps-only text usually looks too tight.
Choosing a unit
You can write letter-spacing in any CSS length unit. The choice matters because it decides what happens when the font size changes.
| Unit | Scales with font size | Typical use |
|---|---|---|
| `em` | Yes, relative to the element's own font size | Almost always the right choice |
| `rem` | No, relative to the root font size | Rarely. The spacing stays fixed when a component's font size changes |
| `px` | No | One-off fixes where you want an exact device-pixel amount |
Tracking is a proportional adjustment. A value that looks right at 12px will be far too tight or loose at 64px if you hard-code pixels. Em units keep the ratio constant, so use them by default.
Converting design-tool values
Design tools such as Figma, Illustrator, and InDesign usually express tracking in thousandths of an em. Divide by 1000 to get the CSS value in em.
function trackingToEm(units) {
return units / 1000;
}
console.log(trackingToEm(75) + 'em'); // "0.075em"
console.log(trackingToEm(-20) + 'em'); // "-0.02em"| Design tool value | CSS value | At 16px font size |
|---|---|---|
| 75 | `0.075em` | 1.2px |
| 120 | `0.12em` | 1.92px |
| -20 | `-0.02em` | -0.32px |
| -40 | `-0.04em` | -0.64px |
Some tools, including Figma, can also show tracking as a percentage. A tracking of 5% is 0.05em. Check which unit the panel displays before you copy a number.
Computation and inheritance
This is the point where intermediate designers most often go wrong. letter-spacing is an inherited property, and what children inherit is the computed length. It is not the em expression you wrote.
The browser converts 0.1em to an absolute length using the font size of the element where the declaration appears. Descendants receive that absolute length, even if their own font size is different.
.card {
font-size: 1rem; /* 16px */
letter-spacing: 0.1em; /* computes to 1.6px */
}
.card h2 {
font-size: 4rem; /* 64px, but inherits 1.6px, not 6.4px */
}The h2 is four times larger than its parent but receives the same 1.6px of added space. That is only 0.025em at its own size. If you want proportional spacing on the heading, declare it on the heading itself:
.card h2 {
font-size: 4rem;
letter-spacing: -0.02em; /* computes to -1.28px for this element */
}A practical rule follows from this. Set letter-spacing on the element whose font size you are tuning, and avoid setting a non-zero em value on a container that holds text of several sizes.
Where the space goes
The spacing is added after each character, and most browsers apply it after the last character of a line too. Two consequences follow.
The trailing space problem
With centered text, the extra space after the final letter pushes the visible text slightly left of true center. The effect is small at 0.02em and noticeable at 0.15em. For a tracked-out centered label, compensate with equal padding on the opposite side:
.centered-label {
text-align: center;
text-transform: uppercase;
letter-spacing: 0.15em;
padding-left: 0.15em; /* offsets the trailing space */
}Padding in em is computed from the element's own font size, so this stays matched to the tracking as long as both are declared on the same element. A negative margin-right of the same amount works as well.
Adding to kerning, not replacing it
Letter-spacing is applied after the font's kerning. A kerned pair like "AV" still gets its pair adjustment, and then your tracking value is added to that. Adding 0.1em to every pair preserves the relative differences between pairs. That is why tracking is safe on text that has already been kerned well.
Letter-spacing and ligatures
When letter-spacing is non-zero, browsers generally do not apply optional ligatures. Letters such as "fi" or "ffl" are spaced individually instead. Support is not uniform across rendering engines, so for predictable tracked all-caps text, turn ligatures off explicitly:
.tracked-caps {
text-transform: uppercase;
letter-spacing: 0.1em;
font-variant-ligatures: none;
}Capital letters rarely have standard ligatures anyway. The declaration matters most when the same rule is shared with mixed-case text.
Scripts that should not be tracked
Cursive scripts such as Arabic connect letters into joined forms. Adding space between the letters breaks those joins and makes text look wrong or hard to read. Apply letter-spacing only to text in scripts that are written as separate letters, or reset it for connected scripts:
:lang(ar) {
letter-spacing: 0;
}If your site is multilingual, a global tracking rule on body or * can quietly damage some languages.
Setting a sensible system
A common approach is to define tracking as design tokens at the level of each text role. This keeps values in one place and avoids inheritance surprises, because each role sets its own em value.
:root {
--tracking-display: -0.02em;
--tracking-body: 0;
--tracking-caps: 0.1em;
}
.display {
font-size: 4rem;
letter-spacing: var(--tracking-display);
}
p {
letter-spacing: var(--tracking-body);
}
.label {
font-size: 0.75rem;
text-transform: uppercase;
letter-spacing: var(--tracking-caps);
}Custom properties hold the em text, but letter-spacing still resolves it against the font size of the element that uses it, so each role gets proportional spacing.
Common mistakes
- Tracking out lowercase body text to "improve readability". Lowercase text relies on tight word shapes. Keep body text at
normalor very close, and change line length or size instead. - Using
pxfor tracking in a responsive layout, so spacing does not scale with fluid type. - Setting
letter-spacingon a wrapper and expecting headings inside to scale it. - Forgetting the trailing space on centered, tracked labels and buttons.
- Copying a design-tool value without dividing by 1000.
Exercise
A design file shows a section label with tracking of 100 in a tool that uses thousandths of an em. The label is 14px and uppercase. What CSS letter-spacing should you write, and how many pixels of extra space does each letter get?
Show answer
Divide 100 by 1000 to get 0.1em, so write letter-spacing: 0.1em;. At 14px, that is 0.1 × 14 = 1.4px added after each letter.
Exercise
A .card has font-size: 1rem (16px) and letter-spacing: 0.1em. Inside it, an h2 has font-size: 3rem and declares no letter-spacing. What spacing does the h2 use, expressed in px and in em relative to the heading's own size? Then say how you would make the heading use a proportional 0.1em.
Show answer
The h2 inherits the computed length 1.6px (0.1 × 16px). Relative to its own 48px size that is about 0.033em. To get 0.1em at the heading's size (4.8px), declare letter-spacing: 0.1em; on the h2 itself.
Exercise
Why might a centered, uppercase button label with letter-spacing: 0.2em look shifted to the left, and what CSS fixes it?
Show answer
The browser adds the tracking after every character including the last, so a trailing gap of 0.2em sits on the right side of the text. Add padding-left: 0.2em; on the same element (or a margin-right: -0.2em;) to balance it.