October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

How to Trim CSS Headline Spacing With `text-box-trim`

Use CSS text-box trimming to align headline text boxes to chosen font metrics instead of compensating with negative margins. Learn the key values and caveats.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For an English headline that should begin at the top of its capital letters and end at the alphabetic baseline, try text-box: trim-both cap alphabetic;. This trims the text box to chosen font metrics instead of using negative margins to compensate for extra space around the text.

Why headline text boxes can look too tall

The visible gap around text is not always caused by margins. Font metrics and line-height also affect the size of a text element’s line box, and different fonts can produce different line-box heights at the same font size. Negative margins can nudge a headline into place, but they do not directly define where its text box should begin or end.

As an Amazon Associate I earn from qualifying purchases.

CSS text-box trimming gives you a direct way to trim the block-start edge, block-end edge, or both to selected font metrics. It addresses text-box spacing; it is not a general fix for unrelated margin, padding, or layout problems.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What `text-box-trim` and `text-box-edge` control

text-box-trim selects which edge to trim. text-box-edge selects the font metric used as the boundary. The text-box shorthand combines both settings.

#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
Setting Effect
text-box-trim: none Default; trims neither edge.
text-box-trim: trim-start Trims the block-start edge only.
text-box-trim: trim-end Trims the block-end edge only.
text-box-trim: trim-both Trims both edges.
text-box-edge: cap alphabetic Uses the top of capital letters as the start boundary and the alphabetic baseline as the end boundary.
text-box-edge: ex alphabetic Uses the top of the lowercase x-height as the start boundary and the alphabetic baseline as the end boundary.

Choose a trim that matches the design

Start with capital tops and the alphabetic baseline

For an English headline intended to start at the tops of capital letters and finish at the alphabetic baseline, use:

h1 {
  text-box: trim-both cap alphabetic;
}

This is a practical starting point, not a universal setting. Check the result with the actual typeface and headline text; the font’s metrics affect where the chosen boundaries fall. For more detail on the shorthand and edge values, see MDN’s `text-box` reference and `text-box-edge` reference.

Trim only the edge that needs correction

If the excess space is only above or below a heading, use trim-start or trim-end rather than trimming both automatically. Which edge and metric to choose depends on the intended optical boundary, typeface, and whether the heading wraps. The available documentation describes the controls, not comparative performance testing.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Preserve intentional breathing room

Leading can provide deliberate visual space around text. Trimming may make a heading, button label, or paragraph feel too tight, so compare the result in the real design rather than applying one rule to every text element. Chrome for Developers discusses text-box trimming as a way to control spacing and alignment in these cases: CSS text-box trimming.

Rank #3
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Check browser and script support

MDN marks the property Baseline 2026 and says it has worked across the latest devices and browser versions since August 2026. Can I Use lists support in current Chrome, Edge, Safari, and Firefox releases in its 2026 table; earlier releases remain unsupported, and support for some other browsers is unknown or absent. Check the versions your audience uses before relying on trimming as the only spacing rule. Can I Use estimates support at 86.46% using its August 2026 StatCounter usage-share period; that is a dated estimate, not a guarantee for every audience. See Can I Use’s compatibility table.

There is also a standards caveat for scripts whose relevant font metrics may be missing. The CSSWG editor’s draft, dated August 11, 2026 and explicitly marked work in progress, gives Hebrew as an example. Test the actual scripts and fonts in your design rather than assuming an English-oriented metric behaves consistently across writing systems: CSS Inline Layout Module Level 3 editor’s draft.

Test the rule in the context where it will be used

  • Check the selected boundary against the actual typeface and text, including headings that wrap.
  • Compare both-edge trimming with a single-edge trim if only one side looks wrong.
  • Review headings, buttons, and paragraphs separately if they rely on intentional leading.
  • Check browser versions and the scripts your audience uses before removing existing spacing fallbacks.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.