hyphenate-limit-lines CSS property
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Want more browser support for this feature? Tell us why.
The hyphenate-limit-lines CSS property specifies the maximum number of consecutive hyphenated lines in an element.
Try it
hyphenate-limit-lines: no-limit;
hyphenate-limit-lines: 2;
hyphenate-limit-lines: 1;
hyphenate-limit-lines: 0;
<section id="default-example">
<p id="example-element" lang="en">
The word supercalifragilisticexpialidocious is a mouthful of nonsensical
syllables.
</p>
</section>
#example-element {
border: 2px dashed #aaa;
font-size: 1.5rem;
text-align: left;
width: 11rem;
hyphens: auto;
}
Syntax
/* Keyword value */
hyphenate-limit-lines: no-limit;
/* <integer> values */
hyphenate-limit-lines: 2;
hyphenate-limit-lines: 1;
hyphenate-limit-lines: 0;
/* Global values */
hyphenate-limit-lines: inherit;
hyphenate-limit-lines: initial;
hyphenate-limit-lines: revert;
hyphenate-limit-lines: revert-layer;
hyphenate-limit-lines: unset;
Values
The property is specified as a single value from the following list:
Description
The hyphenate-limit-lines property lets you limit how many lines in a row can end with a hyphenated word. In narrow or justified text, the browser may need to hyphenate words on several consecutive lines. Many typographic style guides consider a long run of hyphenated lines (sometimes called a "ladder" or "stack") to be distracting and hard to read, and recommend limiting hyphenation to two or three lines.
The <integer> value specifies the maximum number of consecutive lines that can be hyphenated. For example, a value of 2 allows at most two consecutive lines to be hyphenated. A value of 0 prevents any line from ending with a hyphenated word, which effectively disables hyphenation. Negative values are invalid.
Once the specified number of consecutive lines has been hyphenated, the browser won't hyphenate the next line. Instead, it breaks that line at a regular line-break opportunity, such as a space between words. If the line fills up before it can break, the text may overflow. After a line that isn't hyphenated, the count starts again.
The property only has an effect when hyphenation is enabled, for example, by setting hyphens: auto or by including soft hyphens (­) in the text with hyphens: manual.
If overflow-wrap is set to break-word or anywhere, a word that doesn't fit on a line can still be broken to prevent it from overflowing, even after the hyphenate-limit-lines limit has been reached. In this case, the browser may still break the word without inserting a hyphen or ignore the limit.
Formal definition
Value not found in DB!Formal syntax
hyphenate-limit-lines =
no-limit |
<integer [0,∞]>
<integer> =
<number-token>
Examples
>Limiting consecutive hyphenated lines
This example demonstrates how the hyphenate-limit-lines property can be used to limit consecutive hyphenated lines.
HTML
We include two boxes with the same text, including a very long word.
<div class="container">
<p class="no-limit" lang="en">
The word pneumonoultramicroscopicsilicovolcanoconiosis names a lung disease.
</p>
<p class="limit-1" lang="en">
The word pneumonoultramicroscopicsilicovolcanoconiosis names a lung disease.
</p>
</div>
CSS
We include some basic styles, including limiting the width to 10em, which is too narrow to contain our long word. We set each box to hyphens: auto, which, in the narrow container, will cause the long word to break across three lines by default. We then explicitly set hyphenate-limit-lines on one box to the default no-limit value and the other to 1, which allows only one line in a row to end with a hyphen.
.container {
display: flex;
flex-wrap: wrap;
gap: 1rem;
}
p {
margin: 0;
padding: 0.5rem;
border: 2px dashed #999999;
font-size: 1.25rem;
width: 10em;
hyphens: auto;
}
.no-limit {
hyphenate-limit-lines: no-limit;
}
.limit-1 {
hyphenate-limit-lines: 1;
}
Result
The no-limit in the first box allows the long word to be hyphenated as needed to prevent it from overflowing the container. With 1 on the second box, only one line in a row can end with a hyphen. The long word needs two consecutive hyphenated lines to fit, so after the first hyphen, the rest of the word overflows the container.
Specifications
| Specification |
|---|
| CSS Text Module Level 4> # propdef-hyphenate-limit-lines> |