Educational guide to text-wrap
Choose how text is distributed across lines
Compare wrap, balance, and pretty for different content. Learn what nowrap prevents, why stable matters while editing, and how width, fonts, and browsers change the result.
Mental model
The browser chooses breaks inside a box that already has its own width.
- 1 · Available widthinline-size and the font determine how much text fits on each line.
- 2 · Wrapping opportunitiesLanguage, spaces, and breaking rules allow certain breaks.
- 3 · Line selectiontext-wrap chooses between those breaks; it does not create space or change characters.
text-wrap controls automatic line breaks, not box width or font size. wrap allows normal wrapping; nowrap prevents those breaks. balance, pretty, and stable guide the choice between existing wrapping opportunities.
It is a shorthand for text-wrap-mode and text-wrap-style. text-wrap: balance is equivalent to wrap balance. Omitting one part resets it to its initial value: wrap for mode and auto for style. Use longhands to change only one part.
.title { text-wrap: balance; }.title { text-wrap-mode: wrap; text-wrap-style: balance; }wrap and balance for headings
Same content and width; a different composition strategy.
wrap prioritizes normal wrapping. balance aims for similar line lengths in short blocks such as headings or quotations. It does not center text like text-align or guarantee identical line lengths.
A heading with normal and balanced wrapping
text-wrap: wrap
Design interfaces that remain clear when the available width changes
text-wrap: balance
Design interfaces that remain clear when the available width changes
The balance limit depends on the engine: MDN documents up to six lines in Chromium and ten in Firefox. Do not make this a layout contract; normal wrapping may apply beyond the limit. Use it for short blocks and check actual width, translations, and fallback fonts.
wrap and pretty for paragraphs
Better composition does not mean balancing every line.
pretty favors typographic quality over speed. It can avoid a very short last line and improve other breaks. Algorithms vary: Chromium focuses on the end of the paragraph; WebKit may consider the entire paragraph. It does not promise to remove every isolated word.
A paragraph with normal and pretty wrapping
text-wrap: wrap
An interface needs text that can grow with translations and reading preferences. Choosing line breaks carefully improves composition, but does not replace a readable measure, a suitable font, or space between lines. Always check the result with real content.
text-wrap: pretty
An interface needs text that can grow with translations and reading preferences. Choosing line breaks carefully improves composition, but does not replace a readable measure, a suitable font, or space between lines. Always check the result with real content.
Use balance for short headings and pretty for selected prose. Evaluating multiple breaks has a different cost from normal wrapping; avoid imposing one strategy on the entire document without measuring. Neither replaces line-height or a comfortable reading width.
nowrap, forced breaks, and long words
Preventing automatic wrapping can cause overflow.
nowrap preserves forced breaks, such as br, while preventing automatic ones. It does not shrink text or add an ellipsis. This comparison contains scrolling inside the sample; for prose and controls that must grow, allowing wrap is usually preferable.
A long line and an explicit break
text-wrap: wrap
A long piece of text needs room to keep all of its words available.
text-wrap: nowrap
A long piece of text needs room to keep all of its words available.
text-wrap: nowrap + <br>
First explicit line.
Second explicit line.
overflow-wrap solves a different problem: it allows emergency breaks in strings that do not fit, such as URLs. white-space also controls spaces and breaks; a later declaration may reset text-wrap-mode. Check the cascade before blaming balance or pretty for overflow.
stable while editing content
Preserve lines before an edit without blocking reflow.
stable targets editable text: changing a line should not recompose earlier lines because of that edit. It does not freeze layout when width or fonts change, or save content. A static sample may look identical to wrap.
Edit a block with stable
Editable text · text-wrap: stable
Edit the last lines and observe earlier breaks. Changes are not saved.
The recipe keeps wrap as its base and adds stable. CSS.supports can confirm that the value is recognized, but does not certify behavior during editing. A complete editor requires further decisions; this field only tests native wrapping.
Common pitfalls
Check content, width, cascade, and support for the specific value.
balance does not change the heading
- Expected result
- See a different distribution of lines.
- Cause
- It fits on one line, exceeds the engine limit, or already has balanced breaks.
- Solution
- Try a width with a few lines and real content; check the computed value.
The box stays just as wide
- Expected result
- Have the background fit the balanced lines.
- Cause
- text-wrap changes breaks, not inline-size or the container layout.
- Solution
- Design box width separately and avoid depending on the last line length.
pretty leaves a short last line
- Expected result
- Always eliminate an isolated word.
- Cause
- The value may be unsupported or the algorithm cannot find a better composition.
- Solution
- Review support, font, and measure; keep a readable result with wrap.
nowrap makes the page scroll horizontally
- Expected result
- Keep content inside the viewport.
- Cause
- Automatic breaks are prevented without providing space or handling overflow locally.
- Solution
- Allow wrap for content that must grow; reserve nowrap for limited, accessible cases.
stable seems to do nothing
- Expected result
- See a change when selecting it for static text.
- Cause
- Its purpose appears during editing; it is not another form of balance.
- Solution
- Try editable content and check behavior in your target browsers.
Support and compatibility
The shorthand and its values do not share a single support timeline.
The general card does not guarantee every value. balance and pretty have separate entries in Web Platform DX. At the consultation date, MDN BCD lists pretty in Chrome 117 and Safari 26, and not in Firefox; stable starts in Chrome 130, Firefox 121, and Safari 17.5. Review current tables before publishing or setting requirements.
Start with text that wraps and remains readable. Declare wrap before an enhancement and avoid accidentally inheriting nowrap as the base. @supports (text-wrap: pretty) can condition associated styles; it detects syntax, not break quality. Samples use the real engine without polyfills.