CSS PROPERTIES
Expand All|Collapse All
CSS AT-RULES
SPONSORED LINKS

CSS white-space Property

Topic: CSS3 Properties Reference« Prev|Next »

Description

The white-space CSS property specifies how white-space such as spaces, tabs, and newline characters are handled inside the elements.

The following table summarizes the usages context and the version history of this property.

Default value: normal
Applies to: All elements
Inherited: yes
Animatable: No. See animatable properties.
Version: CSS 1, 2, 3

Syntax

The syntax of the property is given with:

white-space: 
normal | pre | nowrap | pre-line | pre-wrap | initial | inherit

The example below shows the white-space property in action.

  • code {
  •     white-space: pre;
  • }
  • p {
  •     white-space: nowrap;
  • }

Property Values

The following table describes the values of this property.

Value Description
normal Sequences of whitespace will collapse into a single whitespace. Line breaks will occur wherever necessary to fill line boxes. This is default value.
nowrap Collapses whitespace as for normal, but suppresses line breaks within text.
pre Sequences of whitespace are preserved. Lines are only broken at preserved newline characters. Acts like the <pre> tag in HTML
pre-line Sequences of whitespace will collapse into a single space character. Line breaks will occur at preserved newline characters, and wherever necessary to fill line boxes.
pre-wrap Sequences of whitespace are preserved. Line breaks will occur at preserved newline characters, and wherever necessary to fill line boxes.
initial Sets this property to its default value.
inherit If specified, the associated element takes the computed value of its parent element white-space property.

Browser Compatibility

The white-space property is supported in all major modern browsers.

Browsers Icon

Basic Support—

  • Firefox 1+
  • Google Chrome 1+
  • Internet Explorer 4+
  • Apple Safari 1+
  • Opera 4+
 

Warning:The value pre-line is not supported in versions prior to Firefox 3.5, Safari 3.0 and Opera 9.5. The values pre-line, pre-wrap and inherit are not supported in Internet Explorer 7 and earlier.


Further Reading

See tutorial on: HTML Text Formatting.

Related properties: letter-spacing, word-spacing.

 
Close

Your Feedback:

 

We would love to hear from you! Please say something.