white-space
The white-space property controls how spaces collapse and whether lines wrap. It is central to code blocks, labels, chat bubbles, and compact UI where line behavior matters.
Overview
The white-space property controls how spaces collapse and whether lines wrap. It is central to code blocks, labels, chat bubbles, and compact UI where line behavior matters.
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 1 | 12 | 1 | 1 | 18 | 1 | |
break-spaces | 76 | 79 | 69 | 13.1 | 76 | 13.4 |
normal | 1 | 12 | 1 | 1 | 18 | 1 |
nowrap | 1 | 12 | 1 | 1 | 18 | 1 |
pre | 1 | 12 | 1 | 1 | 18 | 1 |
pre-line | 1 | 12 | 3.5 | 3 | 18 | 1 |
pre-wrap | 1 | 12 | 3 | 3 | 18 | 1 |
shorthand values Accepts shorthand values | 114 | 114 | 124 | | 114 | |
svg elements On SVG elements | | 12 | 36 | | | |
textarea support Support on `<textarea>` | 1 | 12 | 36 | 1 | 18 | 1 |
| Other | ||||||
| The white-space SVG attribute specifies how whitespace within text should be handled. This includes whether and how white space inside the element is collapsed and whether lines may wrap at unforced soft wrap opportunities. | 1 | 12 | 1 | 1 | 18 | 1 |
- This feature was removed in a later browser version (3.6)
- Available with a vendor prefix: -moz- (1)
- This browser only partially implements this feature
- Only accepts values for `white-space-collapse` and `text-wrap-mode`, not `white-space-trim`.
- This browser only partially implements this feature
- Only accepts values for `white-space-collapse` and `text-wrap-mode`, not `white-space-trim`.
- This browser only partially implements this feature
- Only accepts values for `white-space-collapse` and `text-wrap-mode`, not `white-space-trim`.
- This browser only partially implements this feature
- Only accepts values for `white-space-collapse` and `text-wrap-mode`, not `white-space-trim`.
- This feature was removed in a later browser version (79)
Syntax
.nowrap { white-space: nowrap; }
.preserve { white-space: pre-wrap; }
code { white-space: pre; } Live demo
Use cases
Code and preformatted text
Preserve spacing and line breaks in snippets, logs, or message previews where exact text layout matters.
Controlled wrapping
Keep badges, labels, or compact cards readable by deciding whether text should wrap, collapse, or stay on one line.
Cautions
- Aggressive nowrap usage can easily cause overflow on small screens.
- Preserving whitespace improves fidelity, but it can also surface unwanted spacing from source markup.
Accessibility
- Readable line wrapping is important for zoomed layouts and narrow viewports.
- Do not force horizontal scrolling for ordinary prose when simple wrapping would keep the content usable.
Related links
Powered by web-features