CSS white-spaceProperty


Example

Specifies that text in a paragraph does not wrap:

p { white-space:nowrap; }

Try it Yourself »

Property definition and usage instructions

The white-space property specifies how whitespace 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 indicate the first browser version that supports the property.

Property
white-space 1.0 5.5 3.5 3.0 9.5

Syntax

/* 值 */
white-space: normal;
white-space: nowrap;
white-space: pre;
white-space: pre-wrap;
white-space: pre-line;
white-space: break-spaces;

/* 全局值 */
white-space: inherit;
white-space: initial;
white-space: revert;
white-space: revert-layer;
white-space: unset;

Property value

Value Description
normal Default. White space will be ignored by the browser.
pre Whitespace is preserved by the browser. Its behavior is similar to the <pre> tag in HTML.
nowrap Text will not wrap; it will continue on the same line until a <br> tag is encountered.
pre-wrap Whitespace sequences are preserved, but line breaks occur normally.
pre-line Whitespace sequences are collapsed, but line breaks are preserved.
inherit Specifies that the value of the white-space property should be inherited from the parent element.

Behavior of various white-space values:

Newline Spaces and tabs Text Wrapping Trailing Spaces
normal Merge Merge line break Delete
nowrap Merge Merge nowrap Delete
pre retain retain nowrap retain
pre-wrap retain retain line break suspend
pre-line retain Merge line break Delete
break-spaces retain retain line break line break


Related Articles

CSS Tutorial:CSS Text

other extensions