I once visited a type foundry in Barcelona, in Poblenou, back when the neighbourhood was still big print shops and factories. They let me take a few pieces of lead type home. I was thrilled. I found out later that a piece of lead type is, more or less, a small block of poison, and that “wash your hands after” wasn’t a figure of speech.

Hold one of those pieces and this whole article is in your hand. The letter sits on top of a block of lead, and the block is taller than the letter. It has to be. Every piece in a font is cast on the same height of body so the lines lock up square, and that height has to fit the tallest accent and the longest descender. A capital H sits in the middle of it with bare metal above and below.

The web kept the lead. Every line of text on this page still sits on an invisible block of metal, and CSS measures from the block. That’s why padding: 15px on a button comes out as 20px from the top of the capitals, and why a layout never quite matches the design file. text-box is the property that finally lets you pull the lead off. Here’s a poster. The grey under each line is its lead, and the red rules are where its capitals and baseline are supposed to land. Lift the lead off a line and watch where it goes.

The poster. Red rules: where each line's capitals and baseline should land.

Tap a line to lift its lead, or pull it all at once.

set it in

Your browser doesn’t support text-box yet, so the type stays on its lead here.

.poster {
  display: flex;
  flex-direction: column;
  gap: 24px;                            /* paper between the ink */
}
.poster > * {
  text-box: trim-both cap alphabetic;   /* pull the lead */
}

Years later I worked in a print shop, back when pages still went to film. Film only has the ink on it. If the layout said 4mm between a headline and a photo, you measured 4mm from the letters, because there was nothing else on the film to measure from. The red rules are that: the poster as it would have been set on film.

With the lead in, every block brings its own air and the air adds up. The kicker is 5px low, the headline 20px, and by the footer the type is nearly 50px off its rules. Nothing’s broken. That’s CSS measuring from the metal. Lift it line by line and you can watch each one drop onto its rules while everything below it moves up. Pull it all and every box is cut to the capitals and the baseline, the 24px gaps are 24px of paper, and the type lands where the layout said.

Turn on inspect and the grey goes blue. That’s the same overlay DevTools paints when you hover an element, and blue is the content box: the box CSS thinks is the text. On the button and the tag, the green is the padding you wrote, and the blue inside it runs past the letters, about 4px each way on the poster’s button. That’s the lead, sitting inside the content box where padding can’t reach it, and it grows with the type. At 20px, like the button in the opening:

.button {
  font-size: 20px;
  padding: 15px 28px;  /* what you wrote */
}
/* what you see: 15px of padding + ~5px of lead = 20px to the capitals */

Then set the poster in Space Mono or Georgia. Same CSS, same 24px gaps, and the drift changes, because every typeface was cast on a different block.

The rest of this is how that works, one proof at a time. A proof is the test sheet you pull before the real run, to see what’s wrong. Most of mine had something wrong, and there’s a section near the end about those.

The block is bigger than the letter

Digital fonts kept the body of the sort, which is what a typesetter calls one piece of type. Every font file declares an ascent and a descent, how far its invisible block reaches above and below the baseline, and the browser builds each line of text out of that block. Pick a font and look at how much of the block the capitals actually use:

Proof 1 · The block of lead, drawn by text-box itself
Type
font

Without text-box support every copy keeps its full box, so the lines collapse onto each other.

/* the same word four times, stacked on one baseline */
.plate { display: grid; align-items: baseline; }
.plate > * { grid-area: 1 / 1; }

/* each copy trimmed to a different edge: its box edges are the lines */
.block  { text-box: trim-both text; }            /* ascent to descent */
.caps   { text-box: trim-both cap alphabetic; }  /* cap height to baseline */
.xs     { text-box: trim-both ex alphabetic; }   /* x-height to baseline */
.letter { color: white; }                        /* the one you read */

The plate is four copies of the same word on one baseline, each trimmed to a different edge, and the edges of their boxes are the lines. The browser already knows where the cap height is. text-box just lets you ask it.

Inspect a line of text and DevTools paints that whole block blue, plus any half-leading, as if all of it were the text. On the plate that block is grey, the same lead as the poster, and none of the grey above the capitals or below the baseline is the letters. How much of it there is, and how evenly it splits around the capitals, is the type designer’s call, the same way it was the typefounder’s. Space Grotesk splits it almost evenly, which is why the poster’s button looked centred even with its lead on: it was only too tall. Space Mono, at the same size, keeps half as much air again above its capitals. A font that keeps more room on top for accents than it leaves under the baseline is the one where a label looks like it’s sinking.

Telling the browser where to cut

text-box is shorthand for two properties. One says which edges to cut, the other says where to cut them.

text-box-trim: trim-both;          /* or trim-start, trim-end, none */
text-box-edge: cap alphabetic;     /* over edge, under edge */

/* same thing */
text-box: trim-both cap alphabetic;

The over edge can be cap, the top of the capitals, ex, the top of the lowercase x, or text, the top of the block itself, which keeps the font’s ascent and only drops the half-leading. The under edge is alphabetic, the baseline, or text again. Try the combinations:

Proof 2 · Pick where to cut, and watch the blue
over
under
.button {
  text-box: trim-both cap alphabetic;
}

Look at the umlaut and the descenders. Trimmed to cap alphabetic, the dots on the Ü sit above the blue and the y, p and g hang below it, into the green. That’s on purpose: the content box now measures the capitals and the baseline, and anything outside them borrows the padding. A compositor would call that a kern, a bit of letter hanging off its body.

cap alphabetic is what I’d reach for on buttons, badges and headings. ex alphabetic suits an all-lowercase label, where cap would leave a gap above the x-height that looks like a mistake.

The strips between the lines

To space lines further apart, a typesetter dropped thin strips of lead between them. That’s the leading in line-height, except CSS splits it in two and puts half above each line and half below. Including above the first line, where nobody asked for it.

That’s what breaks a card, where the title is supposed to line up with the top of the thumbnail. Raise the line-height and the first line drifts down. Step through the line-heights with the trim off, then on.

Proof 3 · The red rule is the top of the thumbnail

Trimming the air above a capital letter

Nov 2026 · Typography

line-height
.heading {
  line-height: 1.4;  /* top won't move */
  text-box: trim-start cap alphabetic;
  margin-block-start: 0;
}

With the trim on, a bigger line-height only spaces the lines out between each other. The top of the first capital stays glued to the top of the thumbnail. The usual fake for this is a negative top margin tuned to one font at one line-height, which breaks the first time either of them changes.

Locking up the poster

On a press, once the type is set you lock it up: wedge it tight inside an iron frame so nothing moves when the forme hits the paper. The CSS version of locking up is the snippet under the poster at the top: a flex column with a 24px gap, and every text box trimmed. That’s the whole layout.

The red rules are the same trick as the specimen plate. The poster is in there five times, stacked in one grid cell. Three hidden copies, one per typeface and all with their lead, hold the height, so nothing below the poster ever jumps. The copy you read follows your taps. The copy on top has transparent type, is always trimmed, and draws a rule at the top and bottom of every box:

.rules .line {
  color: transparent;
  text-box: trim-both cap alphabetic;
  box-shadow: inset 0 1px red, inset 0 -1px red;  /* cap line, baseline */
}

Those rules are what a design file shows you when it measures from the letters, which is where this stops being a typography nicety and starts costing teams time.

Where it hurts in a design system

One button with 5px too much air is a nitpick. A design system multiplies it: every component, every size, every brand. The two places it hurts most are text stacked on text, and fonts that change.

Here’s a card the way most systems build one: a title, a line of body copy and a meta line, stacked with gap: var(--space-2), which is 8px. Turn on inspect to see the gap in orange and the text boxes in blue. Then switch brands.

Proof 4 · The 8px token, three brands

Order shipped

Your package left the warehouse this morning.

Tracking · 3 items

brand font
.card-stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);  /* 8px of ink-to-ink */
}
.card-stack > * {
  text-box: trim-both cap alphabetic;
}

The orange is always exactly 8px. Off, the space you see between two lines of text is that 8px plus the air under one and the air over the next. From the title’s baseline to the top of the next capital it measures about 20px, two and a half times the token, and the exact number shifts with the brand font because each one brings its own lead. On, it’s 8px between the letters, in all three.

The design file is where it starts. Figma has a Vertical trim setting on text: switch it from Standard to Cap height to baseline and the text box hugs the letters, so a 12px gap in the file is 12px from the ink, the way it was on film. Code that measures from the lead turns every one of those values into a few pixels more, and the ticket says “spacing doesn’t match Figma” while nobody can agree whose bug it is. With the trim on both sides, a spacing token means the same thing in Figma and in the browser:

.button {
  padding-block: var(--space-3);       /* the 12px from the file, really 12px */
  text-box: trim-both cap alphabetic;
}

That’s one line in the base component, and every button, badge and tag built on it matches the spec without a per-font nudge. The rest of the list, roughly in order of how much it costs to fix later:

  • Brand and theme swaps. A per-font padding nudge is tuned to one typeface. Change the brand font, or ship a white-label theme, and every component that carries a nudge goes off by a different amount.
  • Fixed-height components. Buttons at 32, 40 and 48, badges, chips, tabs. The air grows with the font size, so a small and a large size sharing the same padding tokens don’t come out proportional, and the label never sits optically centred in a fixed height.
  • Alignment with things that aren’t text. An icon next to a label, an avatar next to a name, a tab’s active underline. They all line up with the box, and the box includes the lead.
  • Other languages. Fallback fonts for other scripts bring their own metrics, so the same component changes height depending on the language. And in Spanish or Catalan, the accents on capitals, Á or È, rise above a box trimmed to cap, so leave them some padding to land in.

What broke along the way

My first claim was wrong. The first draft of this opened with “your button label sits low”, because that’s the folklore. Then I measured Space Grotesk: 28% of its size in air above the capitals, 29% below the baseline. It doesn’t sink. It’s just too tall, top and bottom, which is a less dramatic opening and the true one.

The demos took three tries. The specimen plate started as JavaScript measuring the font with <canvas>. It was perfect in Chrome and put the cap-height line in the wrong place on my iPhone. The next version measured with hidden elements trimmed by text-box, which worked, but an article about a CSS property shouldn’t need a script to explain it. Everything here is CSS now: stacked, trimmed copies draw the lines, and :has() reads the switches.

text text isn’t a no-op. I’d assumed trimming to text text did nothing. It doesn’t cut into the font’s block, but it does drop the half-leading, which is exactly how the specimen plate draws the block. And DevTools’ blue content box includes that half-leading, so it’s bigger than the block of lead in the specimen.

What it won’t do for you

It only trims the first line’s top and the last line’s bottom. Everything in between keeps its leading, which is what you want.

It trusts the font. cap comes from the cap height the font file declares, and a font with sloppy metrics trims in the wrong place. Space Grotesk, the font on this site, reports it correctly. Check yours with a capital H before shipping:

/* a trimmed H should touch its outline, top and bottom */
.metrics-check {
  text-box: trim-both cap alphabetic;
  outline: 1px solid red;
}

Accents and descenders poke out, like the Ü and the y in the edge demo. In a button that’s fine, the padding catches them. In a tight stack of headings with no gap, an accent can touch the line above.

Support is Chrome 133, Safari 18.2 and Firefox 154 onwards. Older browsers ignore the property and you get the box you have today, a bit taller than you asked for. If you have a per-font nudge in production, keep it as the fallback and put the trim behind @supports:

.button {
  padding: 0.5em 1.4em 0.46em;    /* old per-font nudge */
}

@supports (text-box: trim-both cap alphabetic) {
  .button {
    padding: 0.75em 1.4em;
    text-box: trim-both cap alphabetic;
  }
}

Poblenou is 22@ now: offices, startups, glass where the print shops were. I work there. Some days I’m writing CSS a few streets from where they used to cast type, and the browser is still setting every line on a block of lead.

You can finally cut it off. You don’t even have to wash your hands after.