CSS white-space Property


Example

Demonstrate different values of the white-space property:

p.a {
  white-space: nowrap;
}

p.b {
  white-space: normal;
}

p.c {
  white-space: pre;
}
Try it Yourself »

Definition and Usage

The white-space property specifies how white-space inside an element is handled.

Show demo ❯

Default value: normal
Inherited: yes
Animatable: no. Read about animatable
Version: CSS1
JavaScript syntax: object.style.whiteSpace="nowrap" Try it

Browser Support

The numbers in the table specify the first browser version that fully supports the property.

Property
white-space 1.0 8.0 3.5 3.0 9.5


CSS Syntax

white-space: normal|nowrap|pre|pre-line|pre-wrap|initial|inherit;

Property Values

Value Description Demo
normal Sequences of whitespace will collapse into a single whitespace. Text will wrap when necessary. This is default Demo ❯
nowrap Sequences of whitespace 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 Demo ❯
pre Whitespace is preserved by the browser. Text will only wrap on line breaks. Acts like the <pre> tag in HTML Demo ❯
pre-line Sequences of whitespace will collapse into a single whitespace. Text will wrap when necessary, and on line breaks Demo ❯
pre-wrap Whitespace is preserved by the browser. Text will wrap when necessary, and on line breaks Demo ❯
initial Sets this property to its default value. Read about initial
inherit Inherits this property from its parent element. Read about inherit

Related Pages

CSS tutorial: CSS Text Spacing

HTML DOM reference: whiteSpace property


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.