CSS white-space Property
Description
The white-space property controls how whitespace characters (spaces, tabs and line breaks) inside an element are treated by the layout engine. At a basic level it decides whether sequences of whitespace are collapsed into a single space or preserved exactly as in the source, whether explicit newlines in the source create line breaks in the rendered output, and whether text is permitted to wrap at normal breaking opportunities. Because those behaviors change how and where line boxes are formed, this property has a direct effect on the visual flow and measured width of text content.
Because it governs both collapsing and wrapping behavior, white-space frequently interacts with other text-wrapping and breaking controls: for example, overflow-wrap and word-break determine how very long words or unbroken strings are handled when wrapping is allowed, while text-overflow is often used where preventing wrapping causes content to be clipped or ellipsized. In practice, changing how whitespace is handled can turn an element that naturally reflows into one that overflows its container (or vice versa), so it’s important to consider how it combines with overflow, width, and layout constraints.
Common use cases include preserving formatting for preformatted text and code samples, ensuring labels/buttons remain on a single line, or keeping specific spacing for typographic or layout reasons. Because it changes break opportunities, the property also affects user interactions like text selection and copy/paste (what exact whitespace is captured), and it can influence layout stability — unwrapped inline content can introduce horizontal scrolling or unexpected shifts if container sizes aren’t managed. When adjusting whitespace behavior, consider both the visual outcome and how the change will interact with the rest of your layout rules.
Definition
- Initial value
- normal
- Applies to
- All elements
- Inherited
- Yes
- Computed value
- As specified
- Animatable
- No
- JavaScript syntax
- object.style.whiteSpace
Interactive Demo
The rusty swing set creaked a lonely lullaby in the twilight, shadows lengthening like grasping fingers across the dew-kissed grass. A lone dandelion seed, adrift on the breeze, whispered secrets of faraway fields, of dandelion suns and galaxies spun from fluff.
Syntax
white-space: normal | pre | nowrap | pre-wrap | pre-line
Values
- normalSequences of whitespace are collapsed. Newline characters in the source are handled as other whitespace. Breaks lines as necessary to fill line boxes.
- preLine breaks and other whitespace are preserved.
- nowrapLike normal, this value collapses white space; but like pre, it does not allow wrapping.
- pre-lineLike normal, this value collapses consecutive spaces and allows wrapping, but preserves segment breaks in the source as forced line breaks.
- pre-wrapLike pre, this value preserves white space; but like normal, it allows wrapping.
- inherit
Example
Browser Support
The following information will show you the current browser support for the CSS white-space property. Hover over a browser icon to see the version that first introduced support for this CSS property.
This property is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 1st January 2026
