Sub topic 3
Where kerning lives: pair tables inside the font
This chapter assumes you know what a glyph, an advance width, and a sidebearing are, and that you have read how default spacing is built. It also assumes you can read basic CSS. Here you will learn where the kerning numbers are stored, how they are structured, and how a browser or design tool finds and applies them.
Kerning is data, not a setting
When you kern a pair like "AV", the tool does not draw anything differently. It looks up a number stored inside the font file. That number says how far to shift the next glyph, in font units, when a specific glyph appears next to another specific glyph.
This has three consequences:
- The font designer decides the default kerning, not your software.
- Two fonts with the same letter shapes can space them differently.
- If a font file has no kerning data, no setting in your app can create it. You would have to kern by hand or use optical kerning, which is covered in the next chapter.
Two places the data can live
A font file is a set of named tables. Kerning can be stored in one of two.
| Table | Era | What it holds | Where it is used |
|---|---|---|---|
| `kern` | Older TrueType | A flat list of glyph pairs with values | Legacy software, some older fonts |
| `GPOS` | OpenType | Lookups attached to the `kern` feature | Nearly all modern fonts and layout engines |
GPOS stands for Glyph Positioning. It is the OpenType table that holds all positioning adjustments, including kerning, mark placement, and superscript offsets. Kerning there is not a table of its own. It is a feature named kern, which points to one or more lookups. A lookup is a rule set that the text shaper runs. The shaper is the engine, such as HarfBuzz or CoreText, that turns characters into positioned glyphs.
Many fonts ship both tables so older software still works. Modern browsers read GPOS when it is present.
Anatomy of a kerning pair
Every adjustment is a record with three parts:
- The first glyph (left, in left-to-right text).
- The second glyph.
- A value in font units, which is normally the change to the first glyph's advance width.
A negative value pulls the pair together. A positive value pushes it apart.
Order matters. The pair "A, V" is a different record from "V, A". They often have similar values, but they are stored and tuned separately. A designer may also kern "T, o" strongly and "o, T" barely at all, because the shapes differ.
Font units are relative to the font's unitsPerEm value. Many fonts use 1000 units per em, and TrueType fonts often use 2048. A value of -80 in a 1000-unit font means 0.08 em, which is the same as -80 in the thousandths-of-an-em units that design tools show. In a 2048-unit font, -80 means about 0.039 em. Always divide by unitsPerEm before comparing values between fonts.
Pair lookups: two storage formats
A full alphabet has thousands of possible pairs once you add accents and punctuation. Fonts use two formats inside a GPOS pair lookup to keep this manageable.
Format 1: individual pairs. Each first glyph lists the specific second glyphs it adjusts. This is precise but uses more space. Designers use it for exceptions, such as a special value for "T" followed by "o".
Format 2: class pairs. Glyphs with similar shapes are grouped into classes. For example, one class might hold "A", "À", "Á", and "Â", and another might hold "V", "W", and "Y". Then the font stores one value for the class pair. This covers many pairs with one number and keeps accented letters consistent with their base letters.
A font normally uses both. Class pairs set the general behavior, and individual pairs override it for special cases. The shaper checks the lookup's subtables in order, and the first one that matches the pair wins. This is why a designer can put the exceptions first and the general classes after them.
Reading kerning data yourself
You can inspect a font with the Python library fontTools (pip install fonttools). This script finds the kern feature, follows its lookups, and prints the individual pairs. It also counts class subtables, which store pairs in groups and are not expanded here.
import sys
from fontTools.ttLib import TTFont
def kern_pairs(path):
font = TTFont(path)
units = font["head"].unitsPerEm
gpos = font["GPOS"].table
lookup_ids = set()
for record in gpos.FeatureList.FeatureRecord:
if record.FeatureTag == "kern":
lookup_ids.update(record.Feature.LookupListIndex)
pairs = []
class_subtables = 0
for index in sorted(lookup_ids):
lookup = gpos.LookupList.Lookup[index]
for subtable in lookup.SubTable:
# Large fonts wrap subtables in an extension lookup.
if subtable.__class__.__name__ == "ExtensionPos":
subtable = subtable.ExtSubTable
if subtable.LookupType != 2: # 2 = pair adjustment
continue
if subtable.Format == 2:
class_subtables += 1
continue
for first, pair_set in zip(subtable.Coverage.glyphs, subtable.PairSet):
for rec in pair_set.PairValueRecord:
value = getattr(rec.Value1, "XAdvance", 0) or 0
pairs.append((first, rec.SecondGlyph, value))
return units, pairs, class_subtables
if __name__ == "__main__":
units, pairs, classes = kern_pairs(sys.argv[1])
print(f"unitsPerEm: {units}")
print(f"individual pairs: {len(pairs)}, class subtables: {classes}")
for first, second, value in pairs[:10]:
print(f"{first} + {second}: {value} units = {value / units:.3f} em")Run it as python kerns.py YourFont.ttf. Some fonts report zero individual pairs and only class subtables. That is normal for fonts that rely mostly on class kerning.
Note that the script reads only pair lookups of type 2 and ignores kern feature lookups of other types. Real fonts can also split kerning by script or language, which this script does not separate.
How apps and CSS reach this data
Design tools and browsers all ask the shaper for the kern feature. The CSS control for it is font-kerning.
body {
font-kerning: normal; /* apply the font's kerning data */
}
.kerning-off {
font-kerning: none; /* skip the kern feature */
}The values work like this:
autolets the browser decide. Most modern browsers apply kerning by default, but they may skip it for performance on very large text or on some devices.normalrequires kerning.nonedisables it.
The same switch is available through the low-level property. These two rules do the same thing:
.a { font-kerning: none; }
.b { font-feature-settings: "kern" 0; }Prefer font-kerning because it is easier to read and does not override other feature settings in the same way. A font-feature-settings declaration replaces the whole list of settings from a parent rule, so a stray value can switch off features you did not mean to touch.
Edge cases and gotchas
- Fonts with no kerning. Some free or bitmap-style fonts have no
kernfeature. Turning kerning on does nothing. Check with the script above or with a font inspector. - Subsetting can strip it. Tools that make web font subsets to save bytes sometimes drop
GPOSor thekernfeature. If your web font looks looser than the same font in a design tool, compare the file sizes and check the table list. - Different tables, different results. If a font has both
kernandGPOSwith different values, software that reads only the older table will space the text differently from software that readsGPOS. - Variable fonts. Kerning values can change along a design axis, such as weight. A bold instance may kern differently from a regular one, even though both come from one file.
- Scripts and languages. The
kernfeature can be tied to a script. Latin kerning does not automatically apply to Greek or Cyrillic unless the font supplies it. - Spaces and punctuation. Kerning pairs can include the space glyph and punctuation. This is why quotation marks and a following letter sometimes look different between fonts.
Summary of the model
The font stores a lookup tree under the kern feature. The shaper walks that tree for each adjacent glyph pair, picks the first match, and adds the value to the first glyph's advance. CSS and design tools only decide whether to run the feature. They do not create the values.
Exercise
A font has unitsPerEm of 2048 and a kerning record for "T" followed by "o" with a value of -123. What is the adjustment in em, and why can you not compare this number directly with a value of -60 from a font with 1000 units per em?
Show answer
-123 / 2048 is about -0.060 em, so the pair is pulled together by about 0.06 em. The raw numbers are in font units, and each font defines the size of a unit by its unitsPerEm. A -60 in a 1000-unit font is exactly -0.060 em, so the two adjustments are nearly the same even though the raw numbers differ by a factor of two. Always divide by unitsPerEm first.
Exercise
Your web font looks well-kerned in Figma but loose in the browser, and font-kerning: normal makes no difference. Name two likely causes found in the font file.
Show answer
The web font file may have been subsetted or converted in a way that removed the GPOS table or the kern feature, so there is no data to apply. Alternatively, the web font may carry only the older kern table, or different values than the version used in Figma. In both cases, inspect the file's tables, for example with fontTools, and re-export the font with its GPOS kerning kept.