CSS text-wrap Playground

See text-wrap: balance, pretty, wrap, and nowrap rendered side-by-side with live font-size and container-width controls.

About This Tool

Modern CSS gives you four useful values for the text-wrap property — wrap, nowrap, balance, and pretty — but the visual difference between them is subtle until you put them next to each other. This playground renders the same string in all four modes simultaneously so you can decide which one fits your headline, paragraph, button, or card.

The tool is a true playground: type any string, drag the font-size slider between 12px and 32px, and drag the container-width slider between 200px and 800px. The four columns reflow live, letting you reproduce the exact viewport where a regression appears. A line-end marker toggle overlays subtle horizontal rules at every line break so it's easy to count lines and spot orphaned widows. The "Generated CSS" panel emits a copy-ready rule for whichever variant you select, and a browser-support banner using CSS.supports('text-wrap', 'pretty') warns you if your current browser falls back to default wrapping.

balance distributes characters evenly across all wrapped lines and is the right choice for headings, card titles, hero copy, and tooltips of around 1–6 lines. The browser tries multiple line-break candidates and picks the one that minimizes raggedness — a process that is O(n²) in the number of break candidates, which is why most engines cap balance at six wrapped lines. pretty, in contrast, optimizes only the last few lines of a paragraph to avoid orphans (a single dangling word) and improve hyphenation; it scales to long-form content without the perf penalty.

If you're working on layout-sensitive components, pair this playground with our Container Query Builder to test how text reflows inside element-sized containers, the Viewport Size Reference to validate at common device widths, and the Google Fonts Pair Finder to combine type choices with optimal wrap settings. The CSS Selector Reference is handy when you need to scope text-wrap to specific descendant elements.

All processing is client-side. Your text never leaves the browser, no analytics are tied to specific input, and the page works offline once loaded — bookmark it as a permanent reference.

How to Use

  1. Paste a real headline, paragraph, or label into the Text content textarea — or click one of the four sample chips (Marketing headline, Product description, Card title, Long paragraph).
  2. Drag the Font size slider (12-32px) to match your design system's typographic scale.
  3. Drag the Container width slider (200-800px) to simulate the parent element where the text will live (cards, sidebars, modals, hero banners).
  4. Compare the four columns: nowrap, wrap (default), balance, and pretty. Each column shows the same text rendered with a different text-wrap value.
  5. Toggle Show line-end markers to overlay horizontal rules at every line break so you can quickly count lines and spot widows.
  6. Click any column header to mark it as active — the Generated CSS panel updates with that variant's snippet.
  7. Press the Copy button (or the Ctrl+Shift+C keyboard shortcut) to copy the generated CSS rule to your clipboard.

Popular Examples

View all 15 examples →

FAQ

What is the CSS text-wrap property?

text-wrap is a CSS property introduced in 2023 that lets you control how the browser breaks lines inside a block of text. Its values include wrap (the default greedy algorithm), nowrap (force a single line), balance (distribute characters evenly across lines, ideal for headings), pretty (optimize the last few lines of a paragraph to avoid orphans), and stable (keep wrapping consistent as content changes — useful for live-edited content). It replaces tedious manual fixes like inserting <wbr>, &nbsp;, or running JavaScript libraries to balance headlines.

What is the difference between text-wrap: balance and text-wrap: pretty?

balance optimizes the entire block so every wrapped line has roughly the same width — best for short text like headlines, card titles, and tooltips (typically 1–6 lines). pretty optimizes only the last few lines of a longer paragraph to avoid orphans (a single trailing word on its own line) and improves hyphenation choices. Use balance for headings; use pretty for body copy. Internally, balance is computationally expensive (often O(n²) in break candidates), which is why browsers cap it at around six lines, while pretty is designed to scale to long-form content.

Which browsers support text-wrap: pretty and balance?

text-wrap: balance shipped in Chrome 114 (May 2023), Edge 114, Firefox 121 (Dec 2023), and Safari 17.5 (May 2024). text-wrap: pretty is newer — it shipped in Chrome 117 (Sep 2023), Edge 117, and Safari 17.5, but Firefox does not support it as of early 2026 and falls back to default wrapping. Always treat balance and pretty as progressive enhancements: the layout must remain readable when the values are ignored. The browser-support banner at the top of this page uses CSS.supports('text-wrap', 'pretty') to warn you if your current browser will not render the pretty column.

When should I actually reach for text-wrap: balance?

Use balance for any short, prominent block of text where ragged line lengths would look amateurish: H1 and H2 headings, card titles in a grid, hero subtitles, modal titles, tooltip bodies, button labels that wrap to two lines, and form labels above inputs. Avoid balance on body paragraphs (use pretty instead), on text that exceeds about six lines (the browser stops balancing past that point), and on text that animates frequently (the cost of recomputing balance on every frame can hurt performance).

Does text-wrap have a performance impact?

Yes, but it is well-bounded. text-wrap: balance is O(n²) in the number of line-break candidates, so browsers limit it to around six wrapped lines (Chrome's default cap is 6, Firefox's is 10) and skip the optimization entirely on longer blocks. text-wrap: pretty is significantly cheaper — it only re-evaluates the last 4 lines of a paragraph by default, so its cost is constant regardless of paragraph length. For static content the cost is negligible; for content that reflows on every keystroke or animation frame, prefer pretty over balance, or apply balance only to the heading element.

How does text-wrap interact with hyphens, white-space, and overflow-wrap?

text-wrap controls where line breaks may happen; the other three control how words break. Use hyphens: auto with text-wrap: pretty for the best paragraph readability — pretty will choose hyphenation points that minimize orphans. white-space: nowrap is the older equivalent of text-wrap: nowrap and still works; you can use either. overflow-wrap: anywhere lets very long unbreakable strings (URLs, long IDs) wrap mid-word as a last resort, regardless of the text-wrap value. The four properties are complementary, not competing.

Is my data safe?

Yes. This playground runs entirely in your browser using vanilla CSS and React state — no text, slider values, or generated CSS are ever sent to a server. The browser support banner uses the local CSS.supports() API, not a remote feature-detection service. There is no analytics tied to your input, and the page works offline once loaded, so you can paste sensitive draft copy or unreleased product names without leaving any trace.

Related Tools