XML technologies / CSS / Advanced websites with CSS / CSS property reference / white-space
(Excerpt from “CSS − Advanced websites with Cascading Stylesheets” by Rachel Andrew & Dan Shafer)
Consecutive spaces and tabs in HTML are collapsed to single spaces. Line breaks occur only through automatic wrapping or tags <br/> in the HTML code.
To create consecutive spaces or manually controlled line breaks, HTML requires tricks using elements such as " ", the attribute nowrap in table tags, and the HTML tag <pre>, none of which were intended for these purposes.
CSS offers a more elegant, standards-compliant solution: the property white-space allows consecutive spaces and control of line breaks in selected elements.
Inherited: yes
Values
This property accepts the following constants:
normal: Content follows normal HTML behavior: spaces collapse and lines wrap automatically.nowrap: Spaces collapse, automatic wrapping is disabled, and line breaks are triggered only by tags<br/>or replaced by generated content (seecontent).pre: Spaces are not collapsed and automatic wrapping is disabled, behaving similarly to the HTML elementpre.
Default value: normal
Compatibility
CSS version: 1
Works in Mozilla, including Netscape 6 and later, Opera and Internet Explorer 5 for Macintosh.
Internet Explorer for Windows supports this property only from version 5.5, and the value pre only in version 6’s Standards-Compliant Mode.
Netscape 4 supports this property except for nowrap.
Example
The following style rule allows consecutive spaces and disables automatic wrapping in elements div of the class screen:
div.screen {
white-space: pre;
}
Copyright © 2006 of the German translation, dpunkt.verlag GmbH
You may print the online version for your private use.
Otherwise, this chapter from “CSS − Anspruchsvolle Websites mit Cascading Stylesheets” is subject to the same conditions as the bound edition: the work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
dpunkt.verlag GmbH, Ringstraße 19, 69115 Heidelberg