English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSS reference manual

CSS @rules

CSS attributes大全

CSS white-Usage and examples of the space property

white-The space CSS property specifies how whitespace (such as spaces, tabs, and newline characters) is handled within an element.

The following table provides usage instructions and version history for this property, as well as the syntax for using this property in JavaScript scripts.

Default value:normal
Applies to:All elements
Inheritance:Yes
Animatable:No.Please see Animation properties.
Version:CSS 1,2,3
JavaScript syntax:object.style.whiteSpace="pre-wrap"

white-space usage syntax

The syntax of this property is as follows:

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

The following examples demonstrate how to use white-space property.

  code {
   white-space: pre;
  }
  p {
   white-space: nowrap;
  }
Test to see‹/›

Property value

The following table describes the value of this property.

ValueDescription
normalWhite space sequences will be folded into a single space. Newline characters will appear where the line box needs to be filled. This is the default value.
nowrapText will not wrap, and text will continue on the same line until the <br> tag is encountered.
prePreserve white space sequences. Lines are only broken at the preserved newline characters. It is similar to the <pre> tag in HTML.
pre-lineMerge white space sequences but preserve newline characters.
pre-wrapPreserve white space sequences. The newline character will appear at the preserved newline and any place that fills the line box.
initialSet this property to its default value.
inheritIf specified, the associated element adopts the white of its parent element-The value of the space property.

Browser compatibility

white-The compatibility of the space property of the browser, the numbers in the table below represent the minimum version number of the browser that supports this property; all mainstream browsers support this property.

  • Firefox 1+

  • Google Chrome1+

  • Internet Explorer 4+

  • Apple Safari 1+

  • Opera 4+

Warning:pre-line Firefox 3.5, Safari 3.0 and Opera 9.5The value pre is not supported in earlier versions. Value pre-line, pre-wrap and inherit in Internet Explorer 7and earlier versions do not support.

For further reading

Please refer to the following tutorials:HTML text formatting.

Related properties:letter-spacing,word-spacing.