Sub topic 9
Controlling kerning in CSS
This chapter covers how CSS turns font kerning on and off, how that differs from letter-spacing, and how to check the result in a browser. It assumes you know what a kerning pair is and that you can read basic CSS. Earlier chapters covered pair tables and the letter-spacing property, so this one stays on the controls that decide whether the font's own kerning data is used.
What the browser does by default
A font that contains kerning data stores it in pair tables. The data may sit in the kern table of the font file, or in the kern feature of the OpenType GPOS table. When a browser lays out text, it looks up each adjacent pair of glyphs and shifts the second glyph by the stored amount. This happens during text shaping, before the glyphs are painted.
Modern browsers apply kerning by default for most text. You usually do not need to write any CSS to get it. The CSS controls matter in three situations:
- You want to compare text with and without kerning to see what the font is doing.
- A browser or a size threshold has switched kerning off and you want it back.
- You need to turn kerning off for a specific piece of text, such as a monospaced-looking label or a test.
The kerning that CSS controls is the font's built-in kerning. It is a different thing from the manual adjustment you make in a design tool between two letters, and from letter-spacing, which adds the same amount everywhere.
The font-kerning property
The font-kerning property controls whether the browser uses the kerning information in the font. It accepts three values.
| Value | Effect |
|---|---|
| `auto` | The browser decides. It may turn kerning off in cases where it judges the cost is not worth it. |
| `normal` | Kerning is applied. |
| `none` | Kerning is not applied. |
A minimal example shows the same text with and without pair kerning:
body {
font-kerning: normal;
}
.kerning-off {
font-kerning: none;
}font-kerning is inherited, so setting it on body applies to everything below unless a rule overrides it. The .kerning-off class gives you a quick way to switch a single element.
Why auto is not always the same everywhere
With auto, the specification lets the browser choose. Historically, some engines turned kerning off for small text or for long blocks of text to improve rendering speed. Current desktop browsers generally kern all text, but behavior on older browsers and some mobile devices has differed. If your design depends on kerning being present, set font-kerning: normal explicitly instead of relying on auto.
The kern feature in font-feature-settings
Kerning is also an OpenType feature with the four-letter tag kern. You can switch it with the lower-level font-feature-settings property:
.no-kern {
font-feature-settings: "kern" 0;
}
.with-kern {
font-feature-settings: "kern" 1;
}For kerning, font-kerning is the better choice. It is a dedicated property with readable values. font-feature-settings is a low-level override, and it has a cascade drawback: a declaration replaces the whole list of feature settings from a parent rather than adding to it. If a parent turns on a feature and a child sets font-feature-settings: "kern" 0, the child's rule does not inherit the parent's other features.
When both properties are set, the low-level property wins for the features it names. Avoid setting both on the same element, because the result is harder to reason about.
Kerning is separate from letter-spacing
Turning font-kerning off removes the pair adjustments. Setting letter-spacing adds or subtracts a fixed amount between every pair of glyphs. These are independent, and they stack.
The effective gap between two glyphs is roughly:
- the right sidebearing of the first glyph, plus
- the left sidebearing of the second glyph, plus
- the kerning value for that pair (if kerning is on), plus
- the
letter-spacingvalue.
This is why tightening headlines with a negative letter-spacing keeps the relative improvements that kerning provides. The kerned pair AV stays tighter than AH after you apply -0.02em to both.
.headline {
font-size: 4rem;
letter-spacing: -0.02em;
}
.eyebrow {
font-size: 0.75rem;
text-transform: uppercase;
letter-spacing: 0.12em;
}The em unit is relative to the element's font size, so the headline's -0.02em is about -1.3px at 4rem (64px) and the eyebrow's 0.12em is about 1.4px at 0.75rem (12px). The same declaration scales when the font size changes.
An experiment: comparing kerning on and off
The fastest way to see what kerning does is to set up two lines of the same text and flip the property. Use pairs that usually have large kerning values, such as AV, To, Ty, WA, and P.
.demo {
font-family: Georgia, serif;
font-size: 5rem;
line-height: 1.1;
}
.demo.on {
font-kerning: normal;
}
.demo.off {
font-kerning: none;
}Apply on to one paragraph and off to another, both containing WAVE Tyler To. In the off line, the diagonal strokes of W, A, and V sit apart, with visible holes. In the on line, they tuck together.
If you see no difference, one of these is usually the cause:
- The font has no kerning data. Some fonts, especially stripped web subsets, drop the
kernfeature to save bytes. - The font failed to load, and the browser is showing a fallback font. Check the Network and Rendered Fonts panels in developer tools.
- A
letter-spacingvalue other than0is hiding the comparison. This does not remove kerning, but a large tracking value makes small kerning differences hard to see.
Tools for checking what the browser applied
Browser developer tools can show which font file was used for a given element. In Firefox, the Fonts panel in the Inspector lists the fonts used and any variation axes. In Chrome and Edge, the Computed tab shows a "Rendered Fonts" section. This tells you whether your web font or the fallback was used, which matters because the fallback has its own kerning data.
To confirm that a font file contains kerning, open it in a font inspection tool and look for a kern feature under GPOS. If the feature is absent, no CSS setting will add it. You would need to use a different font file, or one that was subset without removing layout features.
Interactions to remember
A few behaviors involve kerning in CSS and are easy to trip over.
- Ligatures. Browsers do not apply optional ligatures when
letter-spacingis non-zero. Kerning is not affected by that rule, so tracked text still keeps its pair adjustments. For tracked all-caps text, you can disable ligatures explicitly so rendering stays predictable across engines. - Monospace fonts. Every glyph has the same advance width, and these fonts usually carry no kerning, so the property has no visible effect.
- Text transforms.
text-transform: uppercasechanges which glyphs are shaped. Kerning forAVin capitals comes from a different set of pairs thanavin lowercase. A font may kern its capitals well and its lowercase poorly, or the reverse. - Font substitution. If a web font loads late, the page first shows the fallback font with its own kerning, and the layout can shift when the web font arrives.
.tracked-caps {
text-transform: uppercase;
letter-spacing: 0.1em;
font-variant-ligatures: none;
}Converting design-tool values
Design tools such as Figma, Illustrator, and InDesign typically express tracking in thousandths of an em. A value of 75 means 75/1000 em. To produce the CSS value, divide by 1000 and append em.
function trackingToEm(units) {
return units / 1000;
}
console.log(trackingToEm(75) + 'em'); // "0.075em"
console.log(trackingToEm(-20) + 'em'); // "-0.02em"Note that this conversion applies to tracking. The manual kerning value you type between two letters in a design tool uses the same unit, but CSS has no per-pair property to carry it. To reproduce a hand-kerned pair on the web, wrap the two letters so the first has a small letter-spacing, or adjust the font file itself. Per-pair overrides in markup are fragile, and they break when the text changes or is translated, so use them only for fixed pieces of text such as a logo lockup.
Common mistakes
- Turning kerning off for body text to "fix" a rendering quirk. This degrades spacing in common pairs such as
r.andTe. Check the font and the loading path first. - Using
font-feature-settingsfor kerning. It works, but it overrides other feature settings on the element and is harder to maintain thanfont-kerning. - Expecting
letter-spacingto replace kerning. Uniform spacing cannot fix a pair that is too loose and another that is too tight. - Testing in only one browser. Rendering engines can differ in how
autobehaves, so check your target browsers.
Exercise
A headline in your CSS has font-kerning: none; and letter-spacing: -0.03em;. The pair "AV" looks too loose compared with "AH". Which single change is most likely to fix this, and why does letter-spacing alone not fix it?
Show answer
Change font-kerning to normal. Kerning tightens specific pairs such as "AV" by an amount stored in the font, while letter-spacing shifts every pair by the same amount. With kerning off, "AV" has no pair adjustment, so a uniform negative value moves "AV" and "AH" together and the difference between them remains.
Exercise
A designer specifies tracking of +60 in Figma for an all-caps label. Write the CSS declarations to reproduce it, including the one that keeps ligatures predictable.
Show answer
Divide 60 by 1000 to get 0.06em. Use letter-spacing: 0.06em; with text-transform: uppercase; and font-variant-ligatures: none;.