Property Description
The white-space property sets how white-space inside an element is to be handled.
This property has the following syntax:
white-space: normal|nowrap|pre|pre-line|pre-wrap|initial|inherit;
Property Values
Value | Description |
---|---|
normal | (default) Whitespace sequences will collapse into a single whitespace. Text will wrap as necessary |
nowrap | Whitespace sequences will collapse into a single whitespace. Text will never wrap to the next line. The text continues on the same line until a <br /> tag is encountered |
pre | Whitespace is preserved by the browser. Text will only wrap on line breaks |
pre-line | Whitespace sequences will collapse into a single whitespace. Text will wrap when necessary, and on line breaks |
pre-wrap | Whitespace is preserved by the browser. Text will wrap when necessary, and on line breaks |
initial | Specifies that the value of the property should be set to the default value |
inherit | Specifies that the value of the property should be inherited from the parent element |
Examples
The following example shows the basic use of this property:
<div style="border: solid 1px blue; width: 150px; padding: 6px;">
<p style="white-space: normal;">Some paragraph text
to demonstrate wrapping</p>
</div>
<br/>
<div style="border: solid 1px blue; width: 150px; padding: 6px;">
<p style="white-space: nowrap;">Some paragraph text
to demonstrate wrapping</p>
</div>
This produces the following result:
Some paragraph text to demonstrate wrapping
Some paragraph text to demonstrate wrapping
Browser Support
Chrome | Firefox | IE | Safari | Opera |
---|---|---|---|---|
1.0 | 3.5 | 8.0 | 3.0 | 9.5 |
Miscellaneous Information
Inherited: | Yes |
---|---|
Defined In: | CSS1 |
Default Value: | normal |