There are 2 ways that text can flow across lines within a block of content, such as a paragraph (<p>
) or headings (<h1>–<h6>). These are forced line breaks, that are controlled by the user, and soft line breaks, that are controlled by the browser. The text-wrap
property can be used to prompt the browser how to control the soft line breaks.
The value you choose, for text-wrap
, depends on how many lines of text you anticipate styling, whether the text is contenteditable
, and whether you need to prioritize appearance or performance.
When the styled content will be limited to a short number of lines, such as headings, captions, and blockquotes, text-wrap: balance
can be added to balance the number of characters on each line, enhancing layout quality and legibility. As browsers limit the number of lines impacted by this property, this value's impact on performance is negligible.
For longer sections of text, text-wrap: pretty
can be used. Note that pretty
has a negative effect on performance, so it should be only used for longer blocks of text when the layout is more important than speed.
The stable
value improves user experience when used on content that is contenteditable
. This value ensures that, as the user is editing text, the previous lines in the area being edited remain stable.