CSS white-space Property

❮ Previous Reference Next ❯

Example

.example1 {
  white-space: normal;
}

.example2 {
  white-space: nowrap;
}

.example3 {
  white-space: pre;
}





Lorem Ipsum is simply dummy text of the printing and typesetting industry.


Meaning

The white-space property controls how spaces, tabs, and newline characters are handled in an element.

Note: To make words break within themselves, use overflow-wrap, word-break, or hyphens instead.

The property specifies two things:

Default value:normal
Inherited:Yes
Animatable:No
Version:CSS1
JavaScript syntax:
object.style.whiteSpace="normal|nowrap|pre|pre-line|pre-wrap|break-spaces|initial|inherit|revert|revert-layer|unset";



Standard Syntax

white-space: normal|nowrap|pre|pre-line|pre-wrap|break-spaces|initial|inherit|revert|revert-layer|unset;



Browser Support

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




Status







Property Values

The following table describes the values of this property.

Value Description
normal It collapses multiple whitespace characters into single spaces and automatically wraps lines, as in normal HTML/XHTML.
nowrap It prevents lines from wrapping if they exceed the element’s content width.
pre It makes the element act much like a <pre> tag and preserves all white space.
pre-line It collapses white space, save newlines, which are preserved.
pre-wrap It breaks newlines that would cause text to break out of an element’s box; otherwise, it acts like a pre value.
break-spaces The behavior is identical to that of pre-wrap, except that:
  • Any sequence of preserved white space always takes up space, including at the end of the line.
  • A line breaking opportunity exists after every preserved white space character, including between white space characters.
  • Such preserved spaces take up space and do not hang, and thus affect the box's intrinsic sizes (min-content size and max-content size).
initial Sets this property to its default value.
inherit If specified, the associated element takes the computed value of its parent element animation-delay property.
revert Reverts the cascaded value of the property from its current value to the value the property
revert-layer Rollback styles to the ones specified in previous cascade layers.
unset Resets a property to its inherited value if the property naturally inherits from its parent, and to its initial value if not.



Default CSS Property Values

selectors {
  white-space: normal;
}
❮ Previous Reference Next ❯