text-box
The text-box CSS property sets the spacing above and below text based on a font's typographic features. For example, text-box: trim-both ex alphabetic trims the top to the top of the letter x and the bottom to the bottom of most letters, without descenders.
Modern Web Guidance
How Modern Web Guidance uses this feature
Eliminates font half-leading whitespace above and below text using text-box-trim and text-box-edge (text-box: trim-both cap alphabetic) for precise vertical alignment.
Recommended fallback strategy
Wrap text-box: trim-both cap alphabetic (or text-box-trim) in @supports (text-box: trim-both) rules. Browsers without support retain standard font half-leading, where negative margins can provide an approximate optical adjustment.
Community use cases (3)
Community signal summary
Developers express a strong need for native
text-boxproperties to resolve long-standing architectural pain points surrounding precise vertical text centering and glyph alignment [1]. Primary use cases include achieving pixel-perfect vertical centering in buttons, badges, and layout components without relying on fragile manual pixel offsets [1].Historically, CSS text layout has suffered from uneven line leading and inconsistent font metrics across operating systems [1]. In the meantime, developers are forced to apply brittle CSS hacks, negative margins, or manual vertical adjustments that break when font families, sizes, or localized scripts change [1][2].
Generated by AI from community comments and may contain inaccuracies. Read the comments below for full developer context.
This summary covers all 3 comments, is up to date, and was last updated on September 5, 2026.
Everyone's seen this (in)famous article, but I'll share it here for posterity: https://tonsky.me/blog/centering/
God, Firefox needs this implemented ASAP.
Firefox is currently working on its implementation, with most of it already being available in Nightly — I have some more details in the "Intent to Prototype", and the main tracking bug is Bug 1816038. Hopefully won't be too long before it's available in the release channel!