March 1, 2024
MarkBernstein.org
 

CSS: lh units

LH units are cool. By Andy Bell.

Historically, I’ve used em, ch and ex units to size icons in contexts like buttons so font sizes icon sizes are nice and synced. Using ex units is especially useful because 1ex is the height of the x character in the chosen font and size.

The lh unit is even more useful though because it is relative to the computed line height. This makes sizing icons relatively and aligning them relatively, much easier.

Good browser support, too.