hyphenate-limit-chars: Fine-Tuning Automatic Hyphenation
AI generated
{ }
@
CSS · Typography · Hyphenation
hyphenate-limit-chars in CSS
Deliberately preventing ugly short hyphenation remainders

hyphens: auto enables automatic hyphenation, but without fine-tuning the browser will happily hyphenate where only one or two characters remain before or after the break. hyphenate-limit-chars and its related limit properties define the minimum word length and how many characters must remain before and after the hyphenation point.

14 min read hyphenate-limit-chars · hyphens: auto CSS Text Level 4

1. The problem: automatic hyphenation without fine-tuning

As soon as hyphens: auto is active, the browser looks for a valid break point inside a word at every line break, in order to fill justified or left-aligned text as evenly as possible. Without further constraints, the browser accepts break points that look typographically ugly, for example when only a single character like in a- remains before the hyphen at the end of a line.

Such short hyphenation remainders are not just visually distracting, they also cost readability, because the human eye barely recognizes such a short fragment as a meaningful part of a word, interrupting the flow of reading. This problem shows up especially often with long German compound words that offer many possible break points, whenever hyphenation is left entirely to the browser without limits.

2. Foundation: hyphens: auto and the mandatory lang attribute

The hyphens: auto property enables the browser's language-dependent automatic hyphenation, but strictly requires a correctly set lang attribute on the document or the affected element. Without that attribute, the browser has no way to know which hyphenation dictionary to apply, and leaves text unhyphenated even when hyphens: auto is set.

On multilingual pages, every language switch in the markup must therefore be marked with its own lang attribute on the respective container, otherwise the browser applies the main language's hyphenation rules to foreign-language text too, producing grammatically incorrect break points. In practice this requirement is surprisingly often overlooked.

3. The syntax of hyphenate-limit-chars

hyphenate-limit-chars accepts up to three values: the minimum total word length, the minimum number of characters before the break point, and the minimum number of characters after it. With hyphenate-limit-chars: 6 3 3, a word is only hyphenated if it is at least six characters long and at least three characters remain both before and after the hyphen.

If only one value is given, it applies to the minimum word length, while the characters before and after the break fall back to sensible browser defaults. Two values set word length and the character count required before the break, with the value after the break inherited from it. This graded syntax lets you set exactly the thresholds that matter for a given project with minimal code.


p {
  hyphens: auto;
  /* word at least 6 chars, 3 chars before and after the hyphen */
  hyphenate-limit-chars: 6 3 3;
}

/* More generous variant for narrow columns,
   where more break points are needed */
.narrow-column p {
  hyphens: auto;
  hyphenate-limit-chars: 5 2 2;
}

4. hyphenate-limit-lines: limiting consecutive hyphenations

Even when each individual hyphenation looks clean on its own, a paragraph looks restless when three or four lines in a row each end with a hyphen. The hyphenate-limit-lines property addresses exactly that, defining how many consecutive lines are allowed to end with a hyphenation before the browser instead wraps a line without hyphenation, accepting extra whitespace.

Classic print typography follows a rule of thumb of at most two consecutive hyphenations before reading flow noticeably suffers. hyphenate-limit-lines: 2 implements exactly that rule in the browser and prevents a long paragraph from visually looking like a row of choppy line endings.


article p {
  hyphens: auto;
  hyphenate-limit-chars: 6 3 3;
  hyphenate-limit-lines: 2; /* max. 2 consecutive hyphenations */
}

5. hyphenate-limit-last: avoiding hyphenation at the end of a paragraph or page

A hyphenation in the very last line of a paragraph, or at the end of a printed page, is especially undesirable typographically, because the detached word remainder looks visually lost and is easily missed by a reader continuing on. hyphenate-limit-last lets you exclude hyphenation specifically for these positions, with values like always-end for the paragraph's end or page for the page end in printed or paginated content.

For responsive web layouts, always-end is the most relevant, since a paragraph's last line is often visually shorter than the others, and a hyphenation there looks especially unsettled. For print stylesheets or PDF export via @page rules, the value page is additionally worth setting, to avoid hyphenation right at a page break.


article p {
  hyphens: auto;
  hyphenate-limit-chars: 6 3 3;
  hyphenate-limit-lines: 2;
  hyphenate-limit-last: always-end; /* never hyphenate the last line */
}

@media print {
  article p {
    hyphenate-limit-last: always-page;
  }
}

6. Limitations of automatic hyphenation: when a manual soft hyphen is needed

However well calibrated the automatic limit properties are, the browser's built-in hyphenation dictionary does not know every technical term, product name, or newly coined word that shows up in editorial content. For such words, the browser either does not hyphenate at all, even though a break would make sense, or it skips a break point entirely for lack of a dictionary entry, which can create wide gaps in justified text for very long compound terms.

For exactly these edge cases, the soft hyphen ­ exists, inserted directly into the HTML text at the desired position, becoming visible and producing a hyphen only when a line break is actually needed at that spot. Unlike a regular hyphen, the soft hyphen stays invisible as long as the word fits completely on one line, complementing hyphens: auto exactly where the automatic dictionary reaches its limits.


<p>
  The material designation
  <span lang="en">carbon­fiber­reinforced­plastic</span>
  only hyphenates at the marked spots when needed.
</p>

7. Interaction with responsive column widths

The narrower a text column, the more often the browser needs to find a break point at all to fill justified text evenly, and at the same time each individual hyphenation becomes visually more dominant there, because fewer characters fit per line. For narrow mobile layouts, it can therefore make sense to set slightly more generous thresholds in hyphenate-limit-chars than for wide desktop columns.

Conversely, for very wide columns it is often worth disabling hyphenation entirely, since there is enough space to push a whole word to the next line without visibly tearing apart justified text. A targeted media-query gradation of hyphenation rules adapts the fine-tuning to the actual column width, instead of forcing one fixed rule across every screen size.

8. Practical example: product descriptions in an online shop

Product descriptions in a German-language online shop often contain long compound words like material names or technical terms that, without hyphenation, either overflow a narrow sidebar or mobile layout or create huge gaps in justified text. A properly configured automatic hyphenation directly improves readability here, without editors having to manually insert soft hyphens into every word.

At the same time, product names and brand names should be excluded from automatic hyphenation, because a break in the middle of a brand name looks unprofessional. hyphens: none targeted at the corresponding product-name class handles that, while the rest of the description text keeps benefiting from hyphens: auto.


.product-description {
  hyphens: auto;
  hyphenate-limit-chars: 6 3 3;
  hyphenate-limit-lines: 2;
}

.product-name,
.brand-name {
  hyphens: none; /* never hyphenate brand names */
}

9. Browser support and historical alternatives

The unprefixed properties hyphenate-limit-chars, hyphenate-limit-lines and hyphenate-limit-last come from the CSS Text Level 4 specification and are not yet broadly implemented in every browser. Historically, vendor-specific predecessors existed, such as -webkit-hyphenate-limit-before, -webkit-hyphenate-limit-after and -ms-hyphenate-limit-chars, which offered similar fine-tuning in older Safari and Edge versions.

For production projects, it is worth setting hyphens: auto and a proper lang attribute as a baseline in every case, because that foundation is already broadly supported, and layering the limit properties on top as progressive enhancement. If support for the limit properties is missing, the browser still hyphenates automatically, just using its own, usually already reasonable default thresholds.

Property Controls Example value Effect
hyphens Hyphenation on/off auto Enables language-dependent hyphenation
hyphenate-limit-chars Minimum length, chars before/after 6 3 3 Prevents single-character remainders
hyphenate-limit-lines Consecutive hyphenations 2 Prevents hyphenation cascades
hyphenate-limit-last Hyphenation at paragraph/page end always-end Last line stays unhyphenated

Mironsoft

Modern CSS, layout architecture and rendering performance

CSS that stays maintainable instead of breaking with every change?

We review existing stylesheets for specificity chaos and layout thrashing, then build a CSS architecture with cascade layers, custom properties and modern layout primitives that still makes sense after the tenth feature.

CSS Audit

Systematically uncovering specificity issues, cascade conflicts and unused selectors.

Architecture Refactoring

Introducing cascade layers, custom properties and design tokens cleanly.

Performance Tuning

Fixing layout thrashing, expensive selectors and rendering bottlenecks.

10. Summary

hyphenate-limit-chars: The Essentials at a Glance

Basic requirement

hyphens: auto strictly requires a correct lang attribute, otherwise text stays unhyphenated even with the property set.

Avoiding short remainders

hyphenate-limit-chars: 6 3 3 prevents only one or two characters from remaining before or after the hyphen.

Hyphenation cascades

hyphenate-limit-lines caps consecutive hyphenations, usually at two lines, as is standard in print typography.

Protecting the last line

hyphenate-limit-last: always-end prevents a particularly unsettled-looking hyphenation in a paragraph's last line.

11. FAQ: hyphenate-limit-chars: The Essentials at a Glance

1What exactly does hyphenate-limit-chars do?
The property defines the minimum length a word must have before it can be hyphenated at all, and how many characters must remain before and after the break point.
2Isn't hyphens: auto enough on its own?
hyphens: auto enables hyphenation but does not control how short the resulting fragments may be. Without hyphenate-limit-chars, the browser can hyphenate even with just one character before the break.
3Why does hyphens: auto sometimes not work at all?
Usually the lang attribute is missing on the document or element. Without it, the browser has no way to know which hyphenation dictionary to use and leaves the text unhyphenated.
4How do you read the three values of hyphenate-limit-chars?
The first value is the minimum total word length, the second is the minimum number of characters before the break, the third is the minimum number of characters after the break.
5What does hyphenate-limit-lines do?
The property limits how many consecutive lines may each end with a hyphenation, preventing a paragraph from looking like a row of choppy line endings.
6Why shouldn't the last line of a paragraph be hyphenated?
A hyphenation in the last, often shorter line looks visually unsettled, and the detached word remainder is easily missed on continued reading. hyphenate-limit-last: always-end prevents that specifically.
7Should brand names be hyphenated automatically?
No. For product names and brand names, hyphens: none on the corresponding class is recommended, so they never break in the middle of the word.
8Was there similar control before the unprefixed properties existed?
Yes, older vendor-specific properties like -webkit-hyphenate-limit-before, -webkit-hyphenate-limit-after and -ms-hyphenate-limit-chars offered similar fine-tuning in older Safari and Edge versions.
9What happens if a browser does not support the limit properties?
hyphens: auto keeps working normally, just without the extra fine-tuning. The browser then uses its own, usually already reasonable default thresholds.
10Should narrow mobile columns get different thresholds than wide desktop columns?
Yes, slightly more generous thresholds make sense for narrow columns, since a break point is needed more often there. For very wide columns, hyphenation can even be disabled entirely.