Search w3schools.com:

SHARE THIS PAGE

Style whiteSpace Property

Style Object Reference Style Object

Definition and Usage

The whiteSpace property sets or returns how to handle tabs, line breaks and whitespace in a text.

Syntax

Set the whiteSpace property:

Object.style.whiteSpace="normal|nowrap|pre|inherit"

Return the whiteSpace property:

Object.style.whiteSpace

Value Description
normal Collapses sequences of whitespace, and breaks lines automatically. This is default
nowrap Collapses sequences of whitespace, but does not allow line breaks
pre Line breaks and other whitespace are preserved
inherit The value of the whiteSpace property is inherited from parent element


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The whiteSpace property is supported in all major browsers.

Note: The value "inherit" is not supported in IE7 and earlier. IE8 requires a !DOCTYPE. IE9 supports "inherit".


Example

Example

Preserve line breaks and whitespaces in the text:

<html>
<head>
<script>
function displayResult()
{
document.getElementById("div1").style.whiteSpace="pre";
}
</script>
</head>
<body>

<div id="div1">
This is so    me text. This is some tex   t. This is some
text. This is some text. This is some text. This is some text.
</div>
<br>

<button type="button" onclick="displayResult()">Preserve whitespace/line breaks</button>

</body>
</html>

Try it yourself »


Style Object Reference Style Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]