O'Reilly logo

CSS Pocket Reference, 4th Edition by Eric A. Meyer

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

white-space

Values:

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

Initial value:

normal

Applies to:

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

Inherited:

No

Computed value:

Same as declared value

Description:

Defines how whitespace within an element is handled during layout. normal acts as web browsers have traditionally treated text, in that it reduces any sequence of whitespace to a single space. pre causes whitespace to be treated as in the HTML element pre, with both whitespace and line breaks 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;}

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required