Easy Tutorial
❮ Prop Style Fontsizeadjust Jsref Obj String ❯

Style whiteSpace Property


Definition and Usage

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

Syntax

Set the whiteSpace property:

Return the whiteSpace property:

Value Description
normal Default. Automatically ignores spaces and line breaks.
nowrap Ignores spaces but does not allow line breaks.
pre Line breaks and other spaces are preserved.
inherit The value of the whiteSpace property is inherited from the parent element.

Browser Support

All major browsers support the whiteSpace property.

Note: IE7 and earlier versions do not support the "inherit" value. IE8 only supports "inherit" if the !DOCTYPE is specified. IE9 supports "inherit".


Example

Preserve line breaks and spaces in text:

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>tutorialpro.org(tutorialpro.org)</title> 
<script>
function displayResult(){
    document.getElementById("div1").style.whiteSpace="pre";
}
</script>
</head>
<body>

<div id="div1">
This is some text, this is some text. This is
some text, this is some text, this is some text.
</div>
<br>
<button type="button" onclick="displayResult()">Preserve Line Breaks and Spaces</button>

</body>
</html>

❮ Prop Style Fontsizeadjust Jsref Obj String ❯