Skip to content
Tutorials Center
My learning

Topics

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.

CSS
h1, h2 { text-wrap: balance; }
article p { text-wrap: pretty; }

Try it

Balanced headings and nowrap

Syntax

CSS
text-wrap: <'text-wrap-mode'> || <'text-wrap-style'>

/* common single keywords */
text-wrap: wrap | nowrap | balance | stable | pretty
  • Initial value: wrap (that is, mode wrap and style auto)
  • 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. pretty is 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 balance falls back to normal wrapping.
  • Not a width setter. balance may make a heading look narrower than its box. If you also want to limit the line length, set a max-width or use the ch unit.
  • 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.