white-space

Controls how white space (spaces, tabs, and newlines) inside an element is handled. It can be used to prevent text from wrapping or to preserve multiple spaces and line breaks.

.code-block {
  white-space: pre;
  font-family: monospace;
  /* preserves all spaces and line breaks exactly as typed */
}
Initial value
normal
Inherited
Yes
Applies to
allElements
Animation type
discrete

Values

normalprepre-wrappre-linewhite-space-collapsetext-wrap-mode
Widely available Since 2015 96% global usage

This feature is well established and works across many devices and browser versions. It has been available across browsers since 2015.

Safe to use without fallbacks.

1+
1+
1+
12+
ESC