Open Source

Introducing tailwindcss-textbox-trim

A Tailwind CSS plugin that enables precise typographic alignment using the CSS text-box-trim specification.

MC

Michael Cummings

January 30, 2026 · 2 min read

before and after typography alignment comparison

One thing that has bothered me for years in web development is how difficult it is to align text *perfectly*.

Even when text appears visually centered, there is often hidden spacing above and below the glyphs that throws layouts off.

This spacing is called **internal leading**.

The Problem

Standard web typography includes extra space inside text boxes.

That means elements like:

  • buttons
  • icons
  • images
  • labels
  • never align quite how you'd expect.

    Even when using flexbox or grid, the text itself contains invisible padding.

    The Solution: text-box-trim

    The CSS **Text Box Trim** specification solves this by allowing the browser to trim the excess space around text glyphs.

    This makes text behave more like a normal box model element.

    You can precisely control how text aligns with other UI components.

    Why I Built This

    I ran into this problem repeatedly across projects.

    My initial solution was to create custom utility classes in each app.

    But after doing that a few times I realized:

    this should just be a package.

    So I built **tailwindcss-textbox-trim**.

    What the Package Does

    It provides Tailwind utilities for the new CSS properties:

  • `text-box-trim`
  • `text-box-edge`
  • Example:

    <p class="text-box-trim text-box-edge-cap">
    Perfectly aligned text
    </p>

    Before vs After

    Before: Standard text with excess space.

    After: Text with `text-box-trim` applied, removing the excess space for perfect alignment.

    Before alignment
    Before alignment
    After alignment
    After alignment

    Bonus

    I'm even using this package on this portfolio site.

    So far it has eliminated a bunch of annoying typographic alignment hacks.

    Typography Should Be Predictable

    Modern layout systems give us precise control over positioning.

    Typography should behave the same way.

    Hopefully this package makes that a little easier.


    MC

    Michael Cummings