Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

CSS white-space property

CSS white-space property

Example

Specifies that text in a paragraph should not wrap:

p

{

white-space:

nowrap

;

}

Try it »


Property definition and usage

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 this 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;


Attribute values

Value Description
normal Default. Whitespace is ignored by the browser.
pre Whitespace is preserved by the browser. Its behavior is similar to that in HTML
 标签。
nowrap Text does not wrap; it continues on the same line until it encounters the
tag.
pre-wrap Preserves sequences of whitespace, but wraps normally.
pre-line Collapses sequences of whitespace, but preserves line breaks.
inherit Specifies that the value of the white-space property should be inherited from the parent element.

Behavior of the various white-space values:

Newline Spaces and tabs Text wrapping Trailing spaces at the end of a line
normal Collapse Collapse Newline Delete
nowrap Collapse Collapse No wrap Delete
pre Keep Keep No wrap Keep
pre-wrap Keep Keep Newline Suspend
pre-line Keep Collapse Newline Delete
break-spaces Keep Keep Newline Newline

Related Articles

CSS Tutorial: CSS Text