Paragraphs & wrapping
white-space
white-space decides how the spaces and line breaks written in the HTML are handled, and whether lines wrap.
Syntax
normal | pre | pre-wrap | pre-line | <'white-space-collapse'> || <'text-wrap-mode'>Preview
Code
.box {
white-space: pre-wrap;
}Controls
About
In HTML, runs of spaces and line breaks normally collapse into a single space, and lines wrap at the edge of the box. white-space can keep spaces and line breaks as written, or stop lines from wrapping.
Writing the value
normal: collapses spaces and line breaks, and wraps at the box width. This is the initial value.nowrap: collapses spaces and line breaks, and never wraps. Long lines overflow the box.pre: keeps spaces and line breaks as written, and never wraps. This is the default for the<pre>element.pre-wrap: keeps spaces and line breaks, and also wraps at the box width.pre-line: keeps only line breaks, collapses runs of spaces, and wraps at the box width.break-spaces: almost the same aspre-wrap, but spaces at the end of a line take up room and can wrap too.
The newer syntax
white-space is now a shorthand for white-space-collapse, which handles spaces and line breaks, and text-wrap-mode, which decides whether lines wrap. For example, pre means preserve nowrap and pre-line means preserve-breaks wrap. The buttons on this page only list the long-standing keywords. A value such as preserve nowrap is read as the keyword with the same meaning; combinations with no matching keyword, such as preserve-spaces, can't be loaded.