Style whiteSpace attribute
- Previous Page Visibility
- Next Page Width
- Go to the Previous Level HTML DOM Style Object
Definition and usage
whiteSpace
How to set or return how tabs, line breaks, and spaces are handled in text.
See also:
CSS Tutorial:CSS Text
CSS Reference Manual:white-space attribute
Example
Example 1
Specify that the text within the <div> element should never wrap:
document.getElementById("myDIV").style.whiteSpace = "nowrap";
Example 2
Return the whiteSpace attribute:
alert(document.getElementById("myDiv").style.whiteSpace);
Syntax
Return the whiteSpace attribute:
object.style.whiteSpace
Set the whiteSpace attribute:
object.style.whiteSpace = "normal|nowrap|pre|initial|inherit"
Attribute value
Value | Description |
---|---|
normal |
Whitespace sequences are collapsed into a single space. Text will wrap as needed. Default. |
nowrap |
Whitespace sequences are collapsed into a single space. Text will never wrap to the next line. Text continues on the same line until the <br> tag is encountered. |
pre |
Whitespace is preserved by the browser. Text will only wrap at line breaks. Similar to the <pre> tag in HTML. |
pre-line |
Whitespace sequences are collapsed into a single space. Text will wrap as needed and at line breaks. |
pre-wrap |
Whitespace is preserved by the browser. Text will wrap as needed and at line breaks. |
initial | Set this attribute to its default value. See also initial. |
inherit | This attribute inherits from its parent element. See also inherit. |
Technical details
Default value: | normal |
---|---|
Return value: | A string that indicates how to handle whitespace within elements. |
CSS Version: | CSS1 |
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |
- Previous Page Visibility
- Next Page Width
- Go to the Previous Level HTML DOM Style Object