Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

WebKit 16 min read Deep dive mediumAdept

Better typography with text-wrap pretty

WebKit's implementation of `text-wrap: pretty` in Safari Technology Preview 216 evaluates the whole paragraph rather than one line at a time. It avoids short last lines, improves rag by targeting a wrap range short of the box edge, and reduces hyphenation; it does not yet address rivers. Chromium's version only adjusts the last four lines, and the CSS spec deliberately leaves the improvements up to each browser. Performance depends on paragraph length, not on how many elements use it, so typical paragraphs are safe. `balance` equalizes line lengths and can leave text narrower than its container, while `pretty` still fills the width, so the choice for headlines depends on the design.

Assumes: CSS basics

Related posts

  • WebKit Features in Safari 17.5

    WebKit mediumAdept

    Safari 17.5 ships seven features and 22 bug fixes, led by CSS additions: text-wrap: balance (with the text-wrap-style longhand), the light-dark() color function, @starting-style for entry transitions, and supports() conditions on @import rules. WebKit balances an unlimited number of lines, versus 6 in Chromium and 10 in Firefox, but skips balancing around floats, initial letters, preserved tabs and soft hyphens. Unsupported text-wrap values fall back to auto, so they are safe to use as progressive enhancement. The release also adds AV1 in WebCodecs when a hardware decoder is available, two WebGL extensions, and fixes across accessibility, media, rendering, Web Push and WebRTC.

  • WebKit Features in Safari 16.2

    WebKit mediumAdept

    Safari 16.2 focuses on cross-browser interoperability as part of Interop 2022, with Safari Technology Preview 159 passing 98.5% of the Interop tests. It completes support for `font-variant-alternates` values such as `styleset()`, `swash()` and `ornaments()` along with `@font-feature-values`, and adds `last baseline` alignment for Flexbox and Grid items. A long list of fixes covers CSS layout (flex sizing, scroll snap, text-decoration, aspect-ratio), rendering (transforms, canvas, tables), SharedWorker, and WebDriver on iOS.

  • Release Notes for Safari Technology Preview 243

    WebKit mediumAdept

    Safari Technology Preview 243 ships WebKit changes 310600@main through 312007@main for macOS Tahoe and Sequoia. The bulk of the release is CSS layout and selector fixes, covering flexbox, grid, aspect-ratio, anchor positioning, `:has()` invalidation and CJK line breaking. It also adds `contain: style` for quote counters, the `insert` keyword for `text-autospace` and the `shadowrootslotassignment` attribute. Other changes include accessibility fixes for VoiceOver, an O(n²) fix for parsing large `<select>` lists, an ES module loader rewrite for top-level await correctness, and several regular expression fixes.

  • WebKit Features in Safari 17.4

    WebKit mediumAdept

    Safari 17.4 ships 46 web platform features and 146 bug fixes, alongside completion of WebKit's multi-year rewrite of its inline layout engine. The rewrite retires the 21-year-old legacy line layout code, finishing with a reimplementation of Ruby, and is the starting point for rewriting other formatting contexts, beginning with Flexbox. Headline features include a native HTML switch (`<input type="checkbox" switch>`) that falls back to a checkbox, vertical writing-mode form controls, `align-content` in block and table layout, and the `@scope` rule. The release also adds web app manifest `shortcuts` and `categories` on macOS. `@scope` changes specificity tie-breaking so the rule whose scope root is closest in the DOM wins, so it should be adopted with care.

  • WebKit Features in Safari 18.2

    WebKit mediumAdept

    Safari 18.2 ships 61 new WebKit features and 111 fixes, headlined by cross-document View Transitions (with view-transition-name: auto, transition classes and types, and pageswap/pagereveal events), CSS text-box trimming for optical alignment to cap height, and background-clip: border-area. It also brings modern calc() with division by units, ruby-align/ruby-overhang and unprefixed ruby-position, scrollbar-width and scrollbar-gutter (which has no effect with overlay scrollbars), ::target-text styling for text fragment links, spatial video and photo viewing in visionOS, WebXR enabledFeatures, Genmoji support, WASM garbage collection and HTTPS by default. Code samples show how to apply each feature, and Safari is the first browser to ship text-box, which degrades gracefully as a progressive enhancement.

The quest for software engineering knowledge.

Look:
Layout: