CSS Reference ยท Typography
The text-wrap property
Reference for the CSS text-wrap shorthand: wrap or nowrap plus balance, pretty and stable line-breaking styles, best uses for headings and paragraphs, and support notes.
The text-wrap property is a shorthand for text-wrap-mode, which decides whether text wraps at all, and text-wrap-style, which decides how the browser picks the break points. One keyword usually does the job: balance evens out the lines of a heading, and pretty avoids a very short last line in a paragraph.
h1, h2 { text-wrap: balance; } article p { text-wrap: pretty; }
Try it
Syntax
text-wrap: <'text-wrap-mode'> || <'text-wrap-style'> /* common single keywords */ text-wrap: wrap | nowrap | balance | stable | pretty
- Initial value:
wrap(that is, modewrapand styleauto) - Applies to: text and the elements that contain it
- Inherited: yes
- Animatable: no
- Computed value: as the two longhands
Values
| Value | Description |
|---|---|
wrap |
Lines break normally when they run out of room. |
nowrap |
Text stays on one line and may overflow. Same as white-space: nowrap for wrapping purposes. |
balance |
Makes the lines of a block roughly equal in length. Browsers apply it only to short blocks (a small number of lines). |
pretty |
Prefers a layout with better-looking breaks, mainly avoiding a very short final line. May be slightly slower than normal wrapping. |
stable |
Keeps earlier lines from re-wrapping while you edit later text. Meant for editable content. |
avoid-orphans |
A newer value that avoids leaving a tiny last line. Support is limited, so check a compatibility table. |
Omitting one longhand resets it to its initial value, so text-wrap: balance also sets the mode back to wrap.
Usage notes
- Headings and captions. Balancing is the best use: titles and pull quotes look tidier without manual
<br>tags. - Body text.
prettyis a safe default for paragraphs; it only changes break choices and never changes the text itself. - Not for long blocks. Because balancing tries many layouts, browsers stop at a few lines. A long paragraph with
balancefalls back to normal wrapping. - Not a width setter.
balancemay make a heading look narrower than its box. If you also want to limit the line length, set amax-widthor use thechunit. - Progressive enhancement. Unsupported values are ignored and the text wraps normally, so no fallback is needed.
- Interaction with
white-space. Both properties set the wrap mode. The one that appears later in the cascade wins.
Browser support
text-wrap: balance and nowrap work in current versions of the major browsers; pretty, stable and avoid-orphans have newer or partial support, so check a compatibility table.
Related
text-wrap-modeโ wrap or nowraptext-wrap-styleโ balance, pretty, stablewhite-spaceโ whitespace handling and wrapping- Lesson: Wrapping, Overflow and Hyphens