Name

white-space

Values:

normal | nowrap | pre | pre-wrap | pre-line | inherit

Initial value:

normal

Applies to:

All elements (CSS2.1); block-level elements (CSS2).

Inherited:

No.

Computed value:

As specified.

Description:

This declares how whitespace within an element is handled during layout. normal acts like traditional web browsers, in that it reduces any sequence of whitespace to a single space. pre causes whitespace to be treated as it is in the HTML element pre, with whitespace and returns fully preserved. nowrap prevents an element from line-breaking, as in the “nowrap” attribute for td and th elements in HTML4. The values pre-wrap and pre-line were added in CSS2.1; the former causes the user agent to preserve whitespace while still automatically wrapping lines of text, and the latter honors newline characters within the text while collapsing all other whitespace as per normal.

Examples:

td {white-space: nowrap;}
tt {white-space: pre;}

Supported by:

Firefox, Internet Explorer, Opera, Safari.

Note:

As of this writing, pre-wrap is supported only by Opera 8 and later, whereas pre-line has no known support.

Get CSS Pocket Reference, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.