text-box-trim PlaygroundThe text-box-trim and text-box-edge properties remove the half-leading and over-shoot that browsers add around the text bounding box — what was always making your tightly-padded buttons feel not quite centered. Toggle the values below and see the difference against an untrimmed control.
Every font ships with extra vertical space above the cap line and below the alphabetic baseline — the half-leading. The browser includes that space in the inline box, so when you set padding: 12px 20px on a button, you get a visually uneven top/bottom because the text box was never centered around the glyphs — it was centered around the leading-inflated box.
text-box-trim: trim-both with text-box-edge: cap alphabetic tells the browser to compute the inline box from cap-height down to baseline, so vertical padding sits where you actually expect it. The combined shorthand is text-box: trim-both cap alphabetic.
As of 2025: Safari 18+, Chrome 133+, Edge 133+, Firefox is behind a flag. Wrap in @supports (text-box: trim-both cap alphabetic) to opt in without breaking unsupported browsers. The two long-hand properties unshipped together; older Safari builds support the legacy leading-trim + text-edge draft — the snippet below includes that too.