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.

It is documented as part of the CSS Text specification.

/* Usage Example */
.code-block {
  white-space: pre;
  font-family: monospace;
  /* preserves all spaces and line breaks exactly as typed */
}

/* Syntax */
white-space: normal;
white-space: pre;
white-space: pre-wrap;
white-space: pre-line;
white-space: white-space-collapse;
white-space: text-wrap-mode;

/* Global values */
white-space: inherit;
white-space: initial;
white-space: revert;
white-space: revert-layer;
white-space: unset;
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.

1+
1+
1+
12+
Kinsta

Your first month is free

Managed WordPress hosting for faster sites.

Learn more

New CSS drops.

Join 600+ readers who've survived clearfix hacks.

ESC