CSS white-space Property
Example
Specify that text in paragraphs should not wrap:
p {
white-space: nowrap;
}
Property Definition and Usage
The white-space property specifies how white space inside an element is handled.
| Default value: | normal |
|---|---|
| Inherited: | yes |
| --- | --- |
| Version: | CSS1 |
| --- | --- |
| JavaScript syntax: | object.style.whiteSpace="pre" |
| --- | --- |
Browser Support
The numbers in the table specify the first browser version that fully supports the property.
| Property | |||||
|---|---|---|---|---|---|
| white-space | 1.0 | 5.5 | 3.5 | 3.0 | 9.5 |
Syntax
/* Values */
white-space: normal;
white-space: nowrap;
white-space: pre;
white-space: pre-wrap;
white-space: pre-line;
white-space: break-spaces;
/* Global values */
white-space: inherit;
white-space: initial;
white-space: revert;
white-space: revert-layer;
white-space: unset;
Property Values
| Value | Description |
|---|---|
| normal | Default. Sequential white spaces are collapsed into one. Newline characters in the source are handled as other spaces. Lines are broken as necessary to fill line boxes. |
| pre | Sequential white spaces are preserved. Lines are only broken at newline characters in the source and at <br> elements. |
| nowrap | Collapses white space as for normal, but suppresses line breaks (text wrapping) within text. |
| pre-wrap | Sequential white spaces are preserved. Lines are broken at newline characters, at <br>, and as necessary to fill line boxes. |
| pre-line | Sequential white spaces are collapsed. Lines are broken at newline characters, at <br>, and as necessary to fill line boxes. |
| inherit | The value of the white-space property is inherited from the parent element. |
Behavior of various white-space values:
| New lines | Spaces and tabs | Text wrapping | End-of-line spaces | |
|---|---|---|---|---|
| normal | Collapse | Collapse | Wrap | Remove |
| nowrap | Collapse | Collapse | No wrap | Remove |
| pre | Preserve | Preserve | No wrap | Preserve |
| pre-wrap | Preserve | Preserve | Wrap | Hang |
| pre-line | Preserve | Collapse | Wrap | Remove |
| break-spaces | Preserve | Preserve | Wrap | Wrap |
Related Articles
CSS Tutorial: CSS Text