This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
* Some parts of this feature may have varying levels of support.
The white-space CSS property sets how white space inside an element is handled.
white-space: normal;
white-space: pre;
white-space: pre-wrap;
white-space: pre-line;
white-space: wrap;
white-space: collapse;
white-space: preserve nowrap;
<section class="default-example" id="default-example">
<div id="example-element">
<p>
But ere she from the church-door stepped She smiled and told us why: 'It
was a wicked woman's curse,' Quoth she, 'and what care I?' She smiled, and
smiled, and passed it off Ere from the door she stept—
</p>
</div>
</section>
#example-element {
width: 16rem;
}
#example-element p {
border: 1px solid #c5c5c5;
padding: 0.75rem;
text-align: left;
}
The property specifies two things:
Note: To make words break within themselves, use overflow-wrap, word-break, or hyphens instead.
This property is a shorthand for the following CSS properties:
Note: The spec defines a third constituent property: white-space-trim, which is not implemented in any browser yet.
/* Single keyword values */ white-space: normal; white-space: pre; white-space: pre-wrap; white-space: pre-line; /* white-space-collapse and text-wrap-mode shorthand values */ white-space: nowrap; white-space: wrap; white-space: break-spaces; white-space: collapse; white-space: preserve nowrap; /* Global values */ white-space: inherit; white-space: initial; white-space: revert; white-space: revert-layer; white-space: unset;
The white-space property values can be specified as one or two keywords representing the values for the white-space-collapse and text-wrap-mode properties, or the following special keywords:
normalSequences of white space are collapsed. Newline characters in the source are handled the same as other white spaces. Lines are broken as necessary to fill line boxes. Equivalent to collapse wrap.
preSequences of white space are preserved. Lines are only broken at newline characters in the source and at <br> elements. Equivalent to preserve nowrap.
pre-wrapSequences of white space are preserved. Lines are broken at newline characters, at <br>, and as necessary to fill line boxes. Equivalent to preserve wrap.
pre-lineSequences of white space are collapsed. Lines are broken at newline characters, at <br>, and as necessary to fill line boxes. Equivalent to preserve-breaks wrap.
Note: The white-space property as a shorthand is a relatively new feature (see browser compatibility). Originally, it had six keyword values; now, the value nowrap is instead interpreted as a value for text-wrap-mode, while the value break-spaces is interpreted as a value for white-space-collapse. The above four keywords are still specific to white-space, but they have longhand equivalents. The change to make white-space a shorthand expands acceptable values to even more keywords and combinations, such as wrap and collapse.
The following table summarizes the behavior of these four white-space keyword values:
| New lines | Spaces and tabs | Text wrapping | End-of-line spaces | End-of-line other space separators | |
|---|---|---|---|---|---|
normal | Collapse | Collapse | Wrap | Remove | Hang |
pre | Preserve | Preserve | No wrap | Preserve | No wrap |
pre-wrap | Preserve | Preserve | Wrap | Hang | Hang |
pre-line | Preserve | Collapse | Wrap | Remove | Hang |
A tab defaults to 8 spaces and can be configured using the tab-size property. In the case of normal, nowrap, and pre-line values, every tab is converted to a space (U+0020) character.
Note: There is a distinction made between spaces and other space separators. These are defined as follows:
Spaces (U+0020), tabs (U+0009), and segment breaks (such as newlines).
All other space separators defined in Unicode, other than those already defined as spaces.
Where white space is said to hang, this can affect the size of the box when measured for intrinsic sizing.
| Initial value | normal |
|---|---|
| Applies to | all elements |
| Inherited | yes |
| Computed value | as specified |
| Animation type | discrete |
white-space =
normal |
pre |
nowrap |
pre-wrap |
break-spaces |
pre-line
code {
white-space: pre;
}
pre {
white-space: pre-wrap;
}
<table>
<tr>
<td></td>
<td>Very long content that splits</td>
<td class="nw">Very long content that don't split</td>
</tr>
<tr>
<td class="nw">white-space:</td>
<td>normal</td>
<td>nowrap</td>
</tr>
</table>
table {
border-collapse: collapse;
border: solid black 1px;
width: 250px;
height: 150px;
}
td {
border: solid 1px black;
text-align: center;
}
.nw {
white-space: nowrap;
}
The white-space CSS property can be used to create multiple lines in a <text> element, which does not wrap by default.
The text inside the <text> element needs to be split into multiple lines for the new lines to be detected. After the first line the rest need to have their whitespace removed.
<svg viewBox="0 0 320 150"> <text y="20" x="10">Here is an English paragraph that is broken into multiple lines in the source code so that it can be more easily read and edited in a text editor. </text> </svg>
text {
white-space: break-spaces;
}
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
white-space |
1 | 12 | 1 | 4 | 1 | 18 | 4 | 10.1 | 1 | 1.0 | 4.4 | 1 |
break-spaces |
76 | 79 | 69 | 62 | 13.1 | 76 | 79 | 54 | 13.4 | 12.0 | 76 | 13.4 |
normal |
1 | 12 | 1 | 15 | 1 | 18 | 4 | 14 | 1 | 1.0 | 4.4 | 1 |
nowrap |
1 | 12 | 1 | 4 | 1 | 18 | 4 | 10.1 | 1 | 1.0 | 4.4 | 1 |
pre |
1 | 12 | 1 | 4 | 1 | 18 | 4 | 14 | 1 | 1.0 | 37 | 1 |
pre-line |
1 | 12 | 3.5 | 9.5 | 3 | 18 | 4 | 14 | 1 | 1.0 | 37 | 1 |
pre-wrap |
1 | 12 | 31–3.6 | 8 | 3 | 18 | 4 | 14 | 1 | 1.0 | 37 | 1 |
shorthand_values |
114Only accepts values forwhite-space-collapse and text-wrap-mode, not white-space-trim. |
114Only accepts values forwhite-space-collapse and text-wrap-mode, not white-space-trim. |
124Only accepts values forwhite-space-collapse and text-wrap-mode, not white-space-trim. |
100Only accepts values forwhite-space-collapse and text-wrap-mode, not white-space-trim. |
No | 114Only accepts values forwhite-space-collapse and text-wrap-mode, not white-space-trim. |
124Only accepts values forwhite-space-collapse and text-wrap-mode, not white-space-trim. |
76Only accepts values forwhite-space-collapse and text-wrap-mode, not white-space-trim. |
No | 23.0Only accepts values forwhite-space-collapse and text-wrap-mode, not white-space-trim. |
114Only accepts values forwhite-space-collapse and text-wrap-mode, not white-space-trim. |
No |
svg_elements |
No | 12–79 | 36 | No | No | No | 36 | No | No | No | No | No |
textarea_support |
1 | 12 | 36 | 4 | 1 | 18 | 36 | 14 | 1 | 1.0 | 37 | 1 |
overflow-wrap, word-break, hyphens
tab-size
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/white-space