0:00 / 0:00

CSS Text-Box Trim

Removes extra space above and below text for predictable spacing.

2025

Year
x.comSource
Typography
Tags

The CSS text-box-trim property with trim-both cap alphabetic removes the built-in spacing above and below text that browsers traditionally include. This creates more predictable and precise vertical spacing, especially important for pixel-perfect UI alignment.

Why It Matters

Designers have long struggled with the invisible space that browsers add above capital letters and below the baseline. This new CSS feature gives developers fine-grained control over text box boundaries, making it easier to:

  • Align text vertically with adjacent elements
  • Create consistent spacing in buttons and badges
  • Build tighter typographic layouts without workarounds

How It Works

The text-box-trim: trim-both value removes extra space from both the top and bottom of the text box, while cap alphabetic defines the trimming edges based on the capital letter height (cap) and the alphabetic baseline.

css
.trimmed-text {
  text-box-trim: trim-both cap alphabetic;
}

This CSS feature represents a significant improvement in typographic control for web developers, eliminating the need for negative margins or other hacky solutions.

Rene WangRene Wang·

More Details

We Regulary Update this List

You can get notified by subscribing to our biweekly newsletter. No ads, no spam, just new content.

Interective Error Page

Few people get there, but it's nice to reduce their sadness when they do

Playful
Profile banner
Detail

Detail

@detaildotdesign

Get highlight from your timeline and exclusive content.

10+Exclusive content
160+Followers