Urgent.News

What's breaking now, across thousands of outlets.

Tech

text-box-trim is the best CSS feature in years and nobody's using it yet

For years, you've been fighting the good fight for consistent text spacing in your digital products. But the fact is, all modern browsers quietly fixed that problem while no one was looking. There is a text-box-trim native CSS feature that removes the phantom gap above and below your text. It's amazing! The ghost space nobody talks about There is invisible cushioning in every line of text, which…

For years, digital product designers have battled with inconsistent text spacing across various browsers. However, there's a CSS feature called text-box-trim that quietly resolves this issue without anyone noticing. This native CSS property eliminates the phantom gap above and below text, which is embedded within font metrics and appears both above the cap height and beneath the baseline. Users have encountered this invisible cushioning, particularly in buttons or titles that appear misaligned with accompanying icons.

Traditionally, this issue was addressed using line-height calculations, negative margins, or referencing measurements from design tools like Figma. However, text-box-trim removes the extra space from the text box entirely, without requiring any hacks, negative margins, or guessing. The Syntax Podcast covered this feature along with alpha() and progress().

The Syntax Podcast highlighted that the syntax is straightforward - you simply apply text-box-trim to a problematic heading or button label. Once you do this, you'll notice the ghost gap disappear, as your text perfectly aligns with the letters. This vertical centering and icon alignment issues will no longer occur. It's baffling why this feature hasn't gained more attention, as it offers a simple solution to a long-standing problem.

Despite the industry's resistance to change and the difficulty in adapting to new features, it's disappointing that teams continue to ship line-height hacks they've used for years. This oversight is particularly confusing when considering how easily native platform features can resolve such issues. The cycle repeats itself: a native feature is introduced to solve a real pain point, but teams stick with outdated workarounds out of habit. Only two years later, a framework adds support, and suddenly it's considered cool.

While the feature itself isn't remarkable, its utility is evident. The issue lies in our attitude towards embracing native CSS features. It's worth noting that the industry often overlooks genuinely useful tools, only to later adopt them when frameworks add support. The key takeaway is to try implementing text-box-trim on a troublesome heading or button label and experience the relief of the invisible gap disappearing.

This small change highlights the platform's improvement, and all we can do is pay attention and adapt to these advancements.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

RIP, iPhone Ultra

For many months, tech blogs like ours used the name iPhone Ultra to refer to Apple's rumored foldable iPhone, but the device ended up being named iPhone Duo .

More from Thursday 10 September →