CSS can finally trim the lead above your capitals

Every line of web text still sits on an invisible metal block, like a piece of lead type, with room for the tallest accent and longest descender. That's why padding: 15px on a button ends up as roughly 20px above the caps, and why layouts never match the design file. The new text-box property cuts that slack off. Carmen Ansio explains it with an interactive poster where you can lift the lead off each line.

Carmen Ansio once took a few pieces of lead type home from a foundry in Barcelona’s Poblenou, and later worked in a print shop when pages still went to film. Film only carries the ink, so 4mm between a headline and a photo was measured from the letters. The browser measures from the metal.
text-box says which edges to trim and where: at the top, to the cap height (cap), the x-height (ex) or the edge of the block (text); at the bottom, to the baseline (alphabetic). Ansio reaches for cap alphabetic on buttons, badges and headings, and ex alphabetic on all-lowercase labels. Only the top of the first line and the bottom of the last are trimmed, so spacing between lines inside a paragraph stays as it was.
The extra air hurts most in design systems. On a card built with an 8px spacing token, the visible gap between lines comes out around 20px, and it shifts with the brand font. Figma has a Vertical trim setting for text: turn trimming on in the file and in code, and 12px means the same thing in both. The property trusts the font’s metrics, so Ansio suggests checking yours against a capital H before shipping.
Open the primary source


