CSS white-space attribute
- Previous page visibility
- Next Page widows
Definition and Usage
The white-space property sets how white space is handled within an element.
This property declaration specifies how white space is handled within an element during the layout process. The values pre-wrap and pre-line were added in CSS 2.1.
See Also:
CSS Tutorial:CSS Text
HTML DOM Reference Manual:whiteSpace Property
Example
Specifies that the text within a paragraph should not be wrapped.
p { white-space: nowrap; }
CSS Syntax
white-space: normal|nowrap|pre|pre-line|pre-wrap|initial|inherit;
Property Value
Value | Description |
---|---|
normal | Default. Whitespace is ignored by the browser. |
pre | Whitespace is preserved by the browser. Its behavior is similar to the <pre> tag in HTML. |
nowrap | Text does not wrap. Text continues on the same line until a <br> tag is encountered. |
pre-wrap | Preserves white space sequences, but breaks lines normally. |
pre-line | Collapses white space sequences, but preserves newline characters. |
inherit | Specifies that the value of the white-space attribute should be inherited from the parent element. |
Technical Details
Default Value: | normal |
---|---|
Inheritance: | yes |
Version: | CSS1 |
JavaScript Syntax: | object.style.whiteSpace="pre" |
More examples
- Prevent text wrapping within an element
- This example demonstrates how to prevent text wrapping within an element.
Browser support
The numbers in the table indicate the first browser version that fully supports this attribute.
Chrome | IE / Edge | Firefox | Safari | Opera |
---|---|---|---|---|
1.0 | 8.0 | 3.5 | 3.0 | 9.5 |
- Previous page visibility
- Next Page widows