HTML | DOM Style whiteSpace Property
The Style whiteSpace property in HTML DOM is used to set the whitespace for text content. It returns the whitespace property that is given to the text.
Syntax:
- It returns the whiteSpace property.
object.style.whiteSpace
- It is used to set the whiteSpace property.
object.style.whiteSpace = "normal|nowrap|pre|initial|inherit"
Property Values:
- normal: It is used to collapse the whitespace into single whitespace and wrap the text. It is a default value.
- nowrap: It is used to collapse the whitespace into single whitespace and there is no text wrapping.
- pre: It is used to define the pre-formatted text.
- pre-line: It is used to collapse whitespaces to single whitespace and wrap text on line brakes.
- pre-wrap: It is used to preserve whitespaces and wrap text on line brakes.
- intial: It sets the whiteSpace property to its default value.
- inherit: This property is inherited from its parent element.
Return Value: It returns a string representing the whiteSpace property for an element.
Example 1:
<!DOCTYPE html> <html> <head> <title> DOM Style whiteSpace Property </title> </head> <body> <center> <h1 style = "color:green;"> GeeksForGeeks </h1> <h2> DOM Style whiteSpace Property </h2> <p id = "gfg"> A Computer science portal for geeks A Computer science portal for geeks </p> <button type = "button" onclick = "geeks()"> Change </button> <script> function geeks() { document.getElementById("gfg").style.whiteSpace = "pre-line"; } </script> </center> </body> </html> |
Output:
Before Click on the button:

After Click on the button:

Example 2:
<!DOCTYPE html> <html> <head> <title> DOM Style whiteSpace Property </title> </head> <body> <center> <h1 style = "color:green;"> GeeksForGeeks </h1> <h2> DOM Style whiteSpace Property </h2> <p id = "gfg">A Computer science portal for geeks A Computer science portal for geeks </p> <button type = "button" onclick = "geeks()"> Change </button> <script> function geeks() { document.getElementById("gfg").style.whiteSpace = "pre-wrap"; } </script> </center> </body> </html> |
Output:
Before Click on the button:

After Click on the button:

Supported Browsers: The browser supported by DOM Style whiteSpace property are listed below:
- Apple Safari
- Google Chrome
- Firefox
- Internet Explorer
- Opera
Recommended Posts:
- HTML | DOM Style right Property
- HTML | DOM Style top Property
- HTML | DOM Style animationDuration Property
- HTML | DOM Style borderBottomRightRadius Property
- HTML | DOM Style animationIterationCount Property
- HTML | DOM Style listStyle Property
- HTML | DOM Style animation Property
- HTML | DOM Style borderBottomWidth Property
- HTML | DOM Style backgroundRepeat Property
- HTML | DOM Style borderImageRepeat Property
- HTML | DOM Style animationPlayState Property
- HTML | DOM Style direction Property
- HTML | DOM Style backgroundSize Property
- HTML | DOM Style borderBottomStyle Property
- HTML | DOM Style borderBottomLeftRadius Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : shubham_singh



