Style whiteSpace Property
Example
Specify that the text in the <div> element will never wrap:
document.getElementById("myDIV").style.whiteSpace = "nowrap";
Try it Yourself »
Description
The whiteSpace property sets or returns how to handle tabs, line breaks and whitespace in a text.
Browser Support
Property | |||||
---|---|---|---|---|---|
whiteSpace | Yes | Yes | Yes | Yes | Yes |
Syntax
Return the whiteSpace property:
object.style.whiteSpace
Set the whiteSpace property:
object.style.whiteSpace = "normal|nowrap|pre|initial|inherit"
Property Values
Value | Description |
---|---|
normal | Sequences of whitespace will collapse into a single whitespace. Text will wrap when necessary. This is default |
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 |
pre | Whitespace is preserved by the browser. Text will only wrap on line breaks. Acts like the <pre> tag in HTML |
pre-line | Sequences of whitespace will collapse into a single whitespace. Text will wrap when necessary, and on line breaks |
pre-wrap | Whitespace is preserved by the browser. Text will wrap when necessary, and on line breaks |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
Technical Details
Default Value: | normal |
---|---|
Return Value: | A String, representing how white-space inside an element is handled |
CSS Version | CSS1 |
More Examples
Example
Return the whiteSpace property
alert(document.getElementById("myDiv").style.whiteSpace);
Try it Yourself »
Related Pages
CSS tutorial: CSS Text
CSS reference: white-space property
❮ Style Object
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.