Share this article:
The CSS text-wrap
property is a shorthand for text-wrap-mode
and text-wrap-style
. It controls how text wraps within its container, ensuring better readability and visual appeal. The property supports several values, including balance
, pretty
, stable
, wrap
, and nowrap
, each offering unique behaviors for text wrapping.
One of the most exciting values is balance
, which cleverly balances text across multiple lines, making it look more pleasing and professional. This is especially useful for headings and short paragraphs where uneven line lengths can be visually distracting.
Below, you can interact with a widget that demonstrates how different text-wrap
settings behave. You can resize the div to see how the text adjusts in real-time. Additionally, you can change the default text to see how it affects the layout.
The text-wrap
property supports the following values:
balance
: Attempts to balance the text across multiple lines, ensuring each line has a similar width. This is ideal for headings and short paragraphs, making text look more pleasing and professional.pretty
: Improves the appearance of text wrapping by avoiding awkward line breaks.stable
: Results in the same behavior as wrap
, but with a key difference: when the user is editing the content, the lines above the edited line remain static. This prevents the entire block of text from re-wrapping, providing a more stable editing experience.wrap
: Allows text to wrap normally, breaking lines at appropriate spaces.nowrap
: Prevents text from wrapping, forcing it to stay on a single line.Here are the CSS code snippets for each text-wrap
value:
h2 {
text-wrap: balance;
}
h2 {
text-wrap: pretty;
}
h2 {
text-wrap: stable;
}
h2 {
text-wrap: wrap;
}
h2 {
text-wrap: nowrap;
}
text-wrap: balance
to create visually appealing and professional-looking text layouts, especially for headings and short paragraphs.
balance
and pretty
text wrapping make it easier for users to read and follow the content.pretty
and balance
values create aesthetically pleasing layouts.
As of now, the text-wrap
property is supported in most modern browsers, including Chrome, Firefox, and Edge. For the latest compatibility information, check Can I use.