Mr. Harun paints the same sign twice, one with text-box-trim: the browser measures the cap line and baseline, then the space above the letters and below the…
Why it matters
The space you see differs from the one you wrote, differs again per font, and a lowercase label looks too low. It used to be patched with different top and bottom padding per font (magic numbers). With trim, the padding you write is the space you see, in any font.
The key idea
A line is taller than its letters, trim cuts the rest
Common mistakes
Counting on wide support It is only in Chrome 133+ and Safari 18.2+. Wrap it in @supports (text-box-trim: trim-both) and make sure the untrimmed look still works (the padding is just a little looser).
Forgetting text-box-edgetext-box-trim picks the side to cut; text-box-edge picks the limit. Without an edge it is auto (= text): only the leading goes, the room above the capitals stays. You usually want cap alphabetic.
Using it on a paragraph, hoping every line moves closer Trim only touches the top of the first line and the bottom of the last. The space between lines is line-height.
Try it in this playground
Slide the padding to 0 The sign without trim still has room above and below the letters. That comes from the font (leading, ascent, descent), not the padding.
Set trim-both without text-box-edge The leading goes, but the top stays wider than the bottom: the edge auto = text, so the ascent − cap room stays.
Add text-box-edge: cap alphabetic The space above the capitals and below the baseline becomes exactly the padding.
Type words with a g or a y Its tail drops into the padding: alphabetic trims at the baseline, not at the tip of the tail.