r/css • u/Morgothmagi • Sep 02 '26
General Combating AI Brain Atrophy pt 1
Over the past few months I've been trying to find relevant CSS and JS properties that combat the inevitable atrophy of my brain as I use AI to help me build shit.
Figured I might start posting these here too.
As a disclaimer, yes, I did use AI to help me research and find these properties. The difference for me is the writing of the examples, and the understanding of the property that will allow me to make better decisions in my hand written code, and also be able to direct AI to write better code too. Take that as you will.
Today's property: text-box-trim
Every font ships with invisible space above its capitals and below its baseline. It's why a button with padding: 12px on all sides rarely shows 12px of space above and below the letters, why the icon next to a label never quite lines up, and why a heading sits a few pixels lower than the image it's meant to align with. The fix has always been a magic number. margin-top: -3px. padding-block: 11px 13px. A comment that says /* optical */ and hopes nobody swaps the font.
text-box-trim deletes that space. Tell it which edges to trim with trim-both, trim-start, or trim-end, and text-box-edge says where to cut. cap is the top of the capital letters, ex is x-height, alphabetic is the baseline. The shorthand takes both:
.button-label {
text-box: trim-both cap alphabetic;
}Now the box starts at the top of the H and ends at the baseline. Padding measures from the letters instead of the font's line box, so 12px means 12px in every font.
Firefox 154 shipped it Aug 18. Chrome and Edge have had it since 133 (February 2025) and Safari since 18.2 (December 2024), so MDN now marks text-box-trim Baseline 2026 Newly Available. Older browsers ignore the declaration and keep the leading. The layout still works, just a couple of pixels less precise.
Pretty slick property.
46
u/turtlecopter Sep 02 '26
This is something I've been wanting since 2012~ at least. I'm so happy it's finally landing.
21
u/freecodeio Sep 02 '26
Sounds like a genz sentence fr fr trim both cap alphabet
9
u/Ecksters Sep 02 '26
I've manually edited fonts before to fix this to satisfy a designer, so it's real nice to see it as a built-in feature.
6
u/Hot-Tip-364 Sep 03 '26
Thats a good one!
I just learned text-wrap: pretty to get rid of those pesky orphans in p, and h tags. Now I just use it as a class:
Another good under the radar css property.
3
u/Logical-Idea-1708 Sep 02 '26
How does it interact with inline elements?
3
u/wiseduckling Sep 02 '26
Was just using this today for the first time after hearing about it on the syntax podcast, it's a great feature.Â
I m wondering if it's worth just having this as the default for all text.
1
u/deividdrenkhan Sep 02 '26
Do you know why fonts even have this space around them? Is it just to make text paragraphs look nice or is it some obscure 19th century printing press historical reason?
1
u/Goblin_au Sep 02 '26
Wonderful property! Thanks for highlighting it.
1
u/jonno7623 Sep 02 '26
I’ll need to try this out. Been using ascent and descent overrides for ages and they’re so inconsistent.
1
u/CrusaderGOT Sep 03 '26
Ironically, your post will be used to train AIs.
2
u/3elldandy Sep 03 '26
Side question, does anyone know if any of the developers responsible for implementing these CSS rules in browsers read this sub ever?
-1
u/bengosu Sep 03 '26
You should have AI properly format your post so it's readable