Where letter-spacing stands today

letter-spacing has existed since the earliest days of CSS, yet browsers have spent years diverging not only from the spec but from each other. The property was the subject of a CSSWG discussion that Mozilla's Emilio Cobos flagged as his highlight of a recent working group meeting — a notable pick given that the same meeting covered masonry layout, if() conditionals, anchor positioning and view transitions.

The difficulty for a rendering engine is not whether space is added, but where. A space can be appended to each character, prepended, or split evenly on both sides, and the choice must also account for LTR versus RTL languages. That decision feeds directly into text measurement and line breaking.

What the specification requires

The spec describes letter-spacing as specifying "additional spacing between typographic character units," with negative values permitted subject to implementation-dependent limits. The operative word is between: spacing should sit only in the gaps between characters, never trailing the final one.

Here is the spec's own test case. Given this HTML:

<p>a<span>bb</span>c</p>

and this CSS:

p {
  letter-spacing: 1em;
}

span {
  letter-spacing: 2em;
}

the result should show equal space on both sides of the inner "b".

Letter spacing on paper. The letter spacing is only applied between the letters "b"s

In every major browser, however, the spacing spills past the last letter of the word:

Letter spacing on browsers. The letter spacing is applied between the letters "b"s and on the right-hand side of the last letter "b"

What browsers actually implement

Engine behavior has long been to append the space after every character, including the last. It may not be the correct choice, but the web is built on it: correcting it now would shift text measurement and line breaking across a vast number of pages. The side effects are familiar — trailing gaps on spaced-out elements (hence the padding hacks many of us apply to buttons), drift away from true center in centered text, and, in RTL writing modes, a gap at the start of the line rather than the end.

The engines also disagree on what "end of a character" means. Blink (Chrome, Brave, Opera) and WebKit (Safari) place it on the right-hand side regardless of direction, while Gecko (Firefox) uses the reading end, which for Hebrew and Arabic lands on the left.

Side-by-side comparison of letter spacing on Gecko and Blink/Webkit

Path one: split the spacing

Simply trimming the trailing space is not viable. Pages that already compensate via padding/margin offsets would see those adjustments become obsolete or layout-breaking. The first real remedy, then, is to redefine the property so the extra spacing is applied around each character instead of after it:

Specifies additional spacing applied to each typographic character unit except those with zero advance. The additional spacing is divided equally between the inline-start and -end sides of the typographic character unit. Values may be negative, but there may be implementation-dependent limits.

Text becomes symmetrical, which also fixes centered content — though measurement and line breaking still change, just less severely.

Letter spacing with the symmetrical fix. The letter spacing is equally applied around the letters "b"s
Different examples of letter spacing being distributed between letters and achieving a symmetrical look

Path two: let authors pick

Because even a halved offset can produce unacceptable layout shifts for existing sites, an alternative is an opt-in. A separate property could declare where the space goes, with the exact syntax still undecided:

letter-spacing-justify: [ before | after | left | right | between | around];

Values follow or ignore text direction as their names imply:

  • before: spaced at the start of the letter, according to the language's direction.
  • after: spaced at the end of the letter, according to the language's direction.
  • left: spaced to the left of the letter, regardless of direction.
  • right: spaced to the right of the letter, regardless of direction.
  • between: spaced between characters, per the spec.
  • around: divided around the letter.

Current behavior would remain the default, and letter-spacing would become a shorthand covering both the length and the placement.

letter-spacing: 1px before;
letter-spacing: 1px right;
letter-spacing: 1px around;

letter-spacing: 1px;
/* same as: */
letter-spacing: 1px before;

The outlook

A third option — doing nothing — looks improbable, since the CSSWG has resolved to act on the issue. Whether the group settles on symmetric spacing or the author-facing switch, a fix is possible; until then, existing workarounds continue to encode the flaw into production layouts.