The text-wrap
CSS property controls how text inside an element is wrapped. The different values provide:
- Typographic improvements, for example more balanced line lengths across broken headings
- A way to turn text wrapping off completely.
Syntax
text-wrap: wrap;
text-wrap: nowrap;
text-wrap: balance;
text-wrap: inherit;
text-wrap: initial;
text-wrap: revert;
text-wrap: revert-layer;
text-wrap: unset;
The text-wrap
property is specified as a single keyword chosen from the list of values below.
Values
-
wrap
-
Text is wrapped across lines at appropriate characters (for example spaces, in languages like English that use space separators) to minimize overflow. This is the default value.
-
nowrap
-
Text does not wrap across lines. It will overflow its containing element rather than breaking onto a new line.
-
balance
-
Text is wrapped in a way that best balances the number of characters on each line, enhancing layout quality and legibility. Because counting characters and balancing them across multiple lines is computationally expensive, this value is only supported for blocks of text spanning a limited number of lines (the Chromium implementation uses six wrapped lines or less), meaning that it is useful for cases such as headings or pull quotes.
text-wrap =
wrap |
nowrap |
balance |
stable |
pretty
Basic text wrap value comparison
HTML
<h2 class="wrap" contenteditable="true">
The default behavior; the text in the heading wraps "normally"
</h2>
<h2 class="nowrap" contenteditable="true">
In this case the text in the heading doesn't wrap, and overflows the container
</h2>
<h2 class="balance" contenteditable="true">
In this case the text in the heading is nicely balanced across lines
</h2>
CSS
.wrap {
text-wrap: wrap;
}
.nowrap {
text-wrap: nowrap;
}
.balance {
text-wrap: balance;
}
h2 {
font-size: 2rem;
font-family: sans-serif;
}
Result
The text in the example is editable. Change the text, adding long words, to view how the different line and word lengths impact wrapping.
Specifications
Browser compatibility
|
Desktop |
Mobile |
|
Chrome |
Edge |
Firefox |
Internet Explorer |
Opera |
Safari |
WebView Android |
Chrome Android |
Firefox for Android |
Opera Android |
Safari on IOS |
Samsung Internet |
text-wrap |
114The pretty and stable values are not supported.
|
114The pretty and stable values are not supported.
|
No |
No |
100The pretty and stable values are not supported.
|
No |
114The pretty and stable values are not supported.
|
114The pretty and stable values are not supported.
|
No |
NoThe pretty and stable values are not supported.
|
No |
NoThe pretty and stable values are not supported.
|
pretty |
117 |
117 |
No |
No |
103 |
No |
117 |
117 |
No |
No |
No |
No |