StealThis .dev

text-wrap Balance & Pretty

A live typography playground contrasting CSS text-wrap balance on headings and pretty on body copy against plain wrapping, with toggles for hanging-punctuation and an initial-letter drop cap so you can watch ragged lines, orphans, and widows resolve in real time.

Open in Lab
css
Targets: JS HTML

Code

A side-by-side reading room for modern CSS text-wrapping. The left column renders a headline and article with the new algorithms switched off; the right mirrors the exact same copy with text-wrap: balance evening out the heading’s line lengths and text-wrap: pretty cleaning up the paragraph’s ragged edge and lonely last-line words. A live toggle row lets you flip each property independently so the difference is unmistakable, not theoretical.

Beyond wrapping, the demo layers two more polish features from the CSS Text and Inline modules: hanging-punctuation: first last pulls opening quotes and terminal periods into the margin for a crisper optical edge, and initial-letter: 3 sinks a three-line drop cap at the start of the body. Each control is a real checkbox with visible focus, keyboard support, and an aria-live status line announcing what changed, while a measured-width slider re-flows both columns so you can hunt for orphans and widows at any column width.

It demonstrates the text-wrap shorthand (balance / pretty) plus hanging-punctuation and initial-letter, all feature-detected with @supports and CSS.supports(). Where a browser lacks a property, the toggle is labelled unsupported and the layout degrades gracefully to normal wrapping — no JavaScript layout math, just the browser’s own line breaker doing the work you can now see.