Sub topic 2
Kerning: Adjusting the Space Between Specific Pairs
This chapter assumes you know the basic vocabulary (glyph, baseline, point size) and that each glyph has an advance width and sidebearings, as covered in the previous chapter. You should also be able to read simple CSS. By the end you will know what kerning is, why it exists, how its values are applied, and how to see it working in a browser.
What kerning is
Kerning is a spacing adjustment applied to one specific pair of adjacent glyphs. It changes the distance between those two glyphs and no others.
Default spacing comes from each glyph's advance width and sidebearings. Every glyph carries its own fixed amount of space, and it knows nothing about its neighbor. That works for pairs like "nn" or "oo", where the vertical edges of the shapes sit near the sidebearings. It fails for pairs whose shapes leave a large empty area between them.
The classic example is "AV". The diagonal of the A leans away from the V, and the V leans away from the A. The sidebearings are measured at the glyph's outer limits, so a wide gap opens in the middle of the pair. The pair looks looser than "nn", even though the sidebearings were set sensibly for each letter on its own.
Kerning corrects this. The font stores a number for the pair "A" followed by "V". The layout engine adds that number to the spacing when it sees that pair in a line of text.
Positive and negative values
A kerning value is a signed number.
- A negative value moves the second glyph closer to the first. This is the common case, used for pairs like AV, AT, To, Wa, and Ty.
- A positive value pushes the pair apart. It is rarer. It appears in pairs where two shapes would otherwise crowd each other, such as some combinations of a round letter with a following closing quote.
- Zero means the default sidebearing spacing is already right.
Kerning values are measured in font units. Design tools usually show them in thousandths of an em. An em is the current font size, so a value of -80 means 0.08 of the font size. At 100 px type, that is 8 px closer. At 20 px type, the same -80 is 1.6 px closer. Because the value scales with size, a pair that is kerned correctly at one size stays proportionally correct at another.
How the adjustment is applied
Kerning is added to the advance of the first glyph in the pair. The second glyph is then placed after the adjusted advance. Nothing else moves except the glyphs that follow, which shift together with the second glyph.
The same calculation in code makes the arithmetic explicit. This Python script uses made-up but plausible numbers for a font with 1000 units per em.
UNITS_PER_EM = 1000
advance = {"A": 700, "V": 680}
kern_pairs = {("A", "V"): -80}
def text_width(text, font_size_px):
total = 0
for i, ch in enumerate(text):
total += advance[ch]
if i + 1 < len(text):
total += kern_pairs.get((ch, text[i + 1]), 0)
return total * font_size_px / UNITS_PER_EM
print(text_width("AV", 100)) # 130.0 (with kerning)
print((advance["A"] + advance["V"]) * 100 / UNITS_PER_EM) # 138.0 (without)At 100 px, the kerned pair is 8 px narrower than the unkerned one. The value is looked up for each adjacent pair, so only the A-to-V transition changes.
Pairs worth knowing
Certain letter shapes create gaps over and over. The usual suspects are:
- Capital letters with diagonals or wide overhangs next to each other: AV, AW, AY, AT, LT, LV, LY.
- A capital followed by a lowercase letter that tucks under it: To, Tr, Ta, Wa, Yo, Va, Fa.
- Letters followed by punctuation: P., F,, Y., r., y,.
- Pairs involving quotes and apostrophes, such as "L" followed by a closing quote.
Most lowercase-to-lowercase pairs need little or no kerning, because lowercase letters are built with vertical stems and consistent sidebearings.
Kerning does not change with tracking
Kerning and tracking can both happen on the same line of text, and they add together. If a pair is kerned by -80 and you set tracking of +50, the engine applies both, so the pair ends up 30 units closer than its default sidebearing spacing. Kerning keeps its relative corrections between pairs while tracking shifts every gap by the same amount. The next chapters cover how to tell the two controls apart.
Seeing kerning in the browser
Browsers apply a font's kerning data by default for text. CSS exposes the font-kerning property to control this. The value normal asks for kerning, none turns it off, and auto lets the browser decide.
body {
font-kerning: normal;
}
.kerning-off {
font-kerning: none;
}To compare, put the same text in two elements. Give one the class kerning-off, and look at pairs like "AVA", "To", and "Wa".
.demo {
font-family: Georgia, serif;
font-size: 4rem;
}Here is a minimal page to test it. Save it as an HTML file and open it in a browser.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Kerning on and off</title>
<style>
.demo { font-family: Georgia, serif; font-size: 4rem; margin: 0; }
.on { font-kerning: normal; }
.off { font-kerning: none; }
</style>
</head>
<body>
<p class="demo on">AVA To Wa</p>
<p class="demo off">AVA To Wa</p>
</body>
</html>The second line should look visibly looser around AV, To, and Wa. The difference is larger at big sizes because the correction scales with the font size.
When kerning is not applied
Kerning only happens when the engine has a value for the pair and the glyphs are adjacent. Several situations break either condition.
- Different fonts or styles. Kerning pairs live inside one font. If "A" is in one font and "V" is in another, or one is regular and the other bold, no kerning value exists for that boundary. This happens when a span with a different font wraps one letter in a word.
- Spaces between words. A space is a glyph, and some fonts kern pairs around it, but most fonts do not. Do not rely on kerning to fix gaps between words.
- Fonts without kerning data. Some free or older fonts have little or no kerning. Their spacing will look uneven for exactly the pairs above, and you will need manual adjustments.
- Disabled by the environment. Some apps and rendering paths turn kerning off by default, particularly for small text. Word processors often make it an option you must enable.
- Mixed sizes. If two glyphs in a pair have different sizes, the kerning value scales with the size of the glyph it belongs to, which can look off. Check pairs at size changes by eye.
Common mistakes
- Assuming a gap that looks wrong is always a kerning problem. If every gap in the line is too tight or too loose, that is tracking, and adjusting single pairs will not help.
- Kerning a pair at a small preview size and not checking it at the final size. Small adjustments are invisible at 12 px and obvious at 80 px.
- Over-kerning. If you tighten every capital pair until the letters nearly touch, the line loses its rhythm. The goal is even visual spacing, not the smallest possible gaps.
- Applying manual kerning to live text and then changing the font. Manual values are tuned to one font's shapes, so they do not carry over.
Summary of the working model
- Default spacing comes from sidebearings, which know nothing about neighbors.
- Kerning is a per-pair signed adjustment, stored in the font, added to the first glyph's advance.
- Negative values tighten, positive values loosen.
- The value is in font units, so it scales with size.
- It needs two adjacent glyphs from the same font, and it can be switched off.
Exercise
A font has 1000 units per em. The advance width of "T" is 610, the advance width of "o" is 560, and the kerning value for the pair "To" is -90. At a font size of 50 px, how far from the start of "T" does the origin of "o" sit, with kerning applied? How much narrower is this than without kerning?
Show answer
With kerning, the origin of "o" is at (610 - 90) = 520 units, which is 520 × 50 / 1000 = 26 px from the start of "T". Without kerning it would be at 610 units, or 30.5 px. The kerned pair is 4.5 px closer (90 × 50 / 1000 = 4.5 px).
Exercise
You see that all the gaps in a line of body text look slightly too tight, including pairs such as "nn" and "oo". Is this a kerning problem? Say why, and name what you would adjust.
Show answer
No. Kerning is a per-pair correction for pairs with unusual shapes, so it would not explain uneven tightness across ordinary pairs. A uniform problem across the whole line points to tracking, so you would loosen the tracking (CSS letter-spacing) slightly for the whole run of text.