Safari Technology Preview now ships WebKit's take on text-wrap: pretty. Dropping the declaration into a stylesheet changes how paragraphs break lines: ragging smooths out, hyphenation is used less, typographic orphans on the final line disappear, and large rivers of whitespace become rarer. A single value doing that much work is unusual for CSS, but the more useful story is that the two engines which implement the keyword disagree about what it should do.

A screenshot of paragraph text that demonstrates a short last line, bad rag, bad hyphenation, and a typographic river.
Credit: WebKit Blog

The Chromium and WebKit interpretations

As Jen Simmons explains in the WebKit post, WebKit's version diverges substantially from Chromium's handling of the same feature. The Chrome team's own write-up describes a narrower remit: Chromium confines its adjustments to the last four lines of a paragraph, concentrating on short final lines, with hyphenation touched only when consecutive hyphenated lines occur at the paragraph's end.

Simmons points to performance as the likely reason for the gap. A pretty algorithm that considers more of the text does more computation, particularly on long-form pages where a paragraph may run to hundreds or thousands of lines. WebKit's answer is not indifference to cost, but headroom:

One thing to know as a developer, the performance of text-wrap is not affected by how many elements on the page it’s applied to. Perf concerns emerge as the pretty algorithm takes more and more lines into consideration as it calculates what to do. In WebKit-based browsers or apps, your text element would need to be many hundreds or thousands of lines long to see a performance hit — and that kind of content is unusual on the web. If your content is broken up into typical-length paragraphs, then you have no reason to worry. Use text-wrap: pretty as much as you want, and rely on our browser engineers to ensure your users will not experience any downsides.

Element count is not the variable to watch, then; line count within an element is. Content split into ordinary paragraphs carries no practical penalty in WebKit-based browsers and apps.

The spec leaves the definition open

This divergence is not a standards violation. The specification deliberately declines to pin down what pretty means, so blaming either engine for the mismatch misses the point — and there is no side to pick. From the spec text, with emphasis on the open-ended clause:

The user agent may among other things attempt to avoid excessively short last lines… but it should also improve the layout in additional ways. The precise set of improvements is user agent dependent, and may include things such as: reducing the variation in length between lines; avoiding typographic rivers; prioritizing different classes of soft wrap opportunities, hyphenation opportunities, or justification opportunities; avoiding hyphenation on too many consecutive lines.

Short last lines, line-length variation, rivers, wrap and hyphenation priorities, consecutive hyphenation — the list is a menu rather than a contract. Implementations may draw on some entries and skip others, which is exactly the split the two browsers have produced. Treat the value as a request for good ragging, not a portable recipe for a specific result.