White Space (CSS Property) - white-space: { normal | nowrap | pre | pre-line | pre-wrap | inherit };
Description
This property controls the handling of whitespace inside an element. Whitespace is a collective name for one or more occurrences of the characters space, tab, line feed, carriage return, and form feed. Typically, within an HTML element, user agents will collapse a sequence of whitespace characters into a single space character.
Note that this property only handles whitespace characters; a common beginner’s mistake is to try to use it to prevent floated elements from dropping down if there isn’t enough room on aline.
Example
This style rule makes elements that belong to the "poetry" class retain and render all
whitespace in the document markup:
<code class="css">.poetry {
white-space: pre;
}</code>Value
normal- A value of
normaldictates that sequences
of whitespace will collapse into a single space character. Line
breaks will occur wherever necessary to fill line boxes. nowrap- Specifying
nowrapensures that sequences of
whitespace will collapse into a single space character, but line
breaks will be suppressed. pre- Specifying
preensures that sequences of
whitespace won’t collapse. Lines are only broken at new lines in the
markup (or at occurrences of"\a"in generated
content). pre-line- This value will cause sequences of whitespace to collapse into a
single space character. Line breaks will occur wherever necessary to
fill line boxes, and at new lines in the markup (or at occurrences
of"\a"in generated content). In other words,
it’s likenormalexcept that it’ll honor
explicit line breaks. pre-wrap- Specify
pre-wrapto ensure that sequences
of whitespace won’t collapse. Line breaks will occur wherever
necessary to fill line boxes, and at new lines in the markup (or at
occurrences of"\a"in generated content). In
other words, it’s likepreexcept that it’ll
wrap the text at the end of line boxes.
Compatibility
Internet Explorer: 5.5,6.0.7.0 (Partial)
Firefox 1.0,2.0,3.0 (Partial)
Safari 1.3,2.0,3.0 (Full)
Opera 9.2 (Partial) ,9.5 (Full)
Internet Explorer for Windows versions up to and including 7 don’t support the values
pre-line or pre-wrap. The values normal and pre behave like pre-wrap on textarea elements. The value nowrap behaves like pre-line on textarea elements.
Internet Explorer for Windows versions up to and including 7 don’t support the value inherit.
Firefox versions up to and including 2 don’t support the values pre-line and pre-wrap (although -moz-pre-wrap is similar to the latter). The values normal, nowrap, and pre behave like pre-wrap on textarea elements.
Opera 9.2 and prior versions don’t support the value pre-line. The values normal and pre behave like pre-wrap on textarea elements. The value nowrap behaves like pre-line on textarea elements.