CSS text-wrap: pretty to Stop the Last Line of a Paragraph from Being Too Short
In blog text and card descriptions, the last line of a paragraph sometimes holds just one stray word or a few characters. Adding one line, text-wrap: pretty, to a paragraph makes the browser choose new break points for the last few lines so that the final line is not left short. In the test environment, within the range I tried, the number of lines and the height of the element did not change.
p {
text-wrap: pretty;
}
The test environment was Ubuntu 24.04, Node.js 22.23.5, Playwright 1.63.0, and Chromium 158. The Japanese paragraphs used IPA Gothic and the English paragraphs used DejaVu Sans, both at 16px. I opened the page with Playwright and measured the text and width of each line from the positions of individual characters. I did not test how it renders in Firefox or Safari, vertical writing, or combination with text-align: justify. The browser versions that support each feature are taken from the compatibility data (@mdn/browser-compat-data 8.1.11).
- 1. Applying it to a Japanese paragraph whose last line is only a verb ending
- 2. When the last line is not short, nothing changes
- 3. In long paragraphs, only the last few lines change
- 4. A long single word is not changed, and phrase-based wrapping prevents short lines in the first place
- 5. In unsupported browsers, the declaration is simply ignored
- 6. Writing it once on body makes it inherited by paragraphs inside, with almost no change in layout time
- 7. If you want to prevent it in Firefox too, keep the last words together
Applying it to a Japanese paragraph whose last line is only a verb ending
In the test environment, I put a Japanese sentence meaning roughly "Even on days so busy I'd take any help, if a single character is left alone on the paragraph's last line, the reader's eye stops right there." into a paragraph 216px wide and compared the results. The line contents below are given as English glosses, because the measurements were taken on the Japanese text.
| Line | Unset | text-wrap: pretty |
|---|---|---|
| Line 1 | "so busy I'd take any help" | "so busy I'd take any help" |
| Line 2 | "days, the paragraph's last line holds one" | "days, the paragraph's last line holds one" |
| Line 3 | "character is left alone, the reader's eye" | "character is left alone, the reader's" |
| Line 4 | "stops there" (cut before the final kana) | "eye stops there" (cut before the final kana) |
| Line 5 | only the verb ending "su." | "masu." (verb ending) |
Without the property, each line is filled as far as possible, so line 5 was only the verb ending "su.". With pretty, line 3 was shortened by one character so that the character meaning "eye" moved to line 4, and the last kana "ma" of line 4 moved to line 5, making line 5 the verb ending "masu.". Lines 1 and 2 did not change. The line count stayed at 5, and the element height stayed the same at about 144px.

The same thing happens with English text. At a width of 320px, without the property the fourth line was only the single word "there.", but with pretty it became the two words "stops there." In this example, the change started earlier than in the Japanese one: the break points of lines 1 through 3 all changed.

When the last line is not short, nothing changes
pretty does not rearrange a paragraph every time. In the test environment, I changed the width of a different, somewhat longer Japanese paragraph and an English paragraph from 240px to 480px in steps of 4px, giving 61 widths, and compared the results.
| Paragraph | Widths where the last line became short (unset) | Widths where the last line became short (pretty) | Widths where the line count changed |
|---|---|---|---|
| Japanese (only a verb ending) | 4 of 61 | 0 of 61 | 0 of 61 |
| English (one word only) | 4 of 61 | 0 of 61 | 0 of 61 |
The only widths where the breaks changed were the 4 widths where the last line became short without the property. At all other widths, even with pretty applied, the output from line 1 to the end was the same as without it. For the paragraphs I tested, the appearance did not change at any width where the last line was not short.
Chrome's developer blog explains that, for now, pretty in Chrome 117 mainly works to prevent a single word from being left alone on the last line (an orphan).
In long paragraphs, only the last few lines change
I tested a long English paragraph of 16 to 26 lines by changing its width. When the last line changed from the single word "text." to the two words "long text.", only the last 2 to 4 lines moved. In a 26-line paragraph, lines 23 through 26 changed, and lines 1 through 22 were the same as without the property.
text-wrap: balance is a property for headings that equalizes the length of all lines. In Chromium, it only applies to text of 6 lines or fewer (MDN's page on text-wrap-style). When I applied balance to the first Japanese paragraph, the breaks changed on all 5 lines, and each line came out at 10 to 11 characters. Because the arrangement of the whole paragraph changes, it is not suitable for body text. I use pretty for body paragraphs and balance for headings. The author of the Chrome developer blog article also writes that they use balance for headings and pretty for paragraphs.
A long single word is not changed, and phrase-based wrapping prevents short lines in the first place
Even when the last line is a single word, pretty did not change the breaks if that word was long. I changed the last word of an English paragraph and compared the results at widths where the last line was one word.
| Last-line word | Length of the last line relative to paragraph width | Result with pretty |
|---|---|---|
| paragraph. | 26 to 29% | Became the two words "at paragraph." |
| internationalization. | 47 to 67% | No change |
In Japanese, too, when word-break: auto-phrase (a setting that wraps at phrase boundaries) was also applied, the breaks did not change with or without pretty at any width from 160 to 400px in 8px steps. With this setting, the last line always ended on a phrase unit such as the Japanese phrase meaning "stops right there.", and there was no width where a single character was left alone. According to the compatibility data, auto-phrase is supported only in Chrome and Edge.
In unsupported browsers, the declaration is simply ignored
According to the compatibility data, text-wrap: pretty is supported from the following versions.
| Browser | text-wrap: pretty | text-wrap-style: pretty |
|---|---|---|
| Chrome and Edge | 117 | 130 |
| Safari (including iOS) | 26 | 26 |
| Firefox | Not supported | Not supported |
Firefox does not support pretty. As described in MDN's explanation of CSS error handling, browsers skip declarations with values they do not understand, so in unsupported browsers the wrapping is the same as when the property is unset.
Writing it once on body makes it inherited by paragraphs inside, with almost no change in layout time
text-wrap is a shorthand for text-wrap-mode and text-wrap-style. As the table above shows, the shorthand text-wrap: pretty is available in older versions of Chrome. In the test environment, when I wrote text-wrap: pretty on body, the computed value of text-wrap-style on the p elements inside also became pretty. Because it is inherited, you only need to write it once on an outer element of the body text.
MDN's page on text-wrap-style says that pretty is a slower process that prioritizes appearance over speed, that it can affect performance, and that it should be used when layout matters more than speed. In the test environment, I placed 2000 paragraphs of 320px width and measured the layout time after switching text-wrap, five runs in each of two rounds. Without the property it was 15.7 to 47.4ms, and with pretty it was 16.5 to 38.0ms, which falls within the run-to-run variation. For the Japanese paragraphs, balance took 41.8 to 62.9ms, longer than the unset Japanese case (19.8 to 47.4ms) in many of the runs.
If you want to prevent it in Firefox too, keep the last words together
If you want to avoid a short last line even in browsers where pretty does not work, you can prevent the last two words from breaking apart in the HTML. For English, replace the space between the last two words with (a non-breaking space).
<p>… and the eye stops at paragraph.</p>
In the test environment, without pretty, the last line changed from "paragraph." to "at paragraph."
For Japanese, if you wrap the last few characters in a span with white-space: nowrap, they will not break inside the span. However, this does not always work. In a 216px paragraph, when I wrapped the phrase meaning "stops right there.", the last line became that phrase as intended, but the line before it was reduced to only the four characters meaning "at that spot".
<p>…読む人の目はそこで<span style="white-space: nowrap">止まってしまいます。</span></p>
As in this example, depending on how many characters you wrap, the line before can end up short. Since the person writing the HTML has to decide how many characters to wrap, in browsers that support it, leaving it to pretty takes less effort.





