HTML | DOM Style wordBreak Property

The DOM Style wordBreak Property is used to set or return the word-break property. The word-break property is used to specify how to break the word when the word is reached at the end of the line. The line breaks in the text can occur in a certain wordBreak property.

Syntax:

  • It is used to return the wordbreak Property:
    object.style.wordBreak 
  • It is used to set the wordBreak property:
    object.style.wordBreak = "normal|break-all|keep-all|initial|
    inherit" 

Property Values:

  • normal: This property uses the default line break rules.
  • break-all: It is used to break the words at any character to prevent overflow.
  • Keep-all: It is same as value normal.
  • break-word: It is used to break the words at arbitrary points to prevent overflow.
  • initial: It sets the property to its default value.

Example-1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html
    <head
        <style
            p { 
                width: 140px; 
                border: 1px solid #000000; 
            
              
            #gfg { 
                word-break: normal; 
            
        </style
    </head
    <body
        <center
            <h1>GeeksforGeeks</h1
            <h2>DOM Style wordBreak Property </h2
            <p id="gfg">GeeksforGeeksGeeksGeeks. 
            A computer science portal for geeks .</p
            <button onclick="myGeeks()">Submit</button>
  
                <script>
               function myGeeks() {
         document.getElementById("gfg").style.wordBreak = "break-all";
                }
      </script>
        </center
    </body
</html>                     

chevron_right


Before Clicking On Button :

After Clicking On Button :

Example-2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html
    <head
        <style
            p { 
                width: 140px; 
                border: 1px solid #000000; 
            
              
            #gfg { 
                word-break: break-all; 
            
        </style
    </head
    <body
        <center
            <h1>GeeksforGeeks</h1
            <h2>DOM Style wordBreak Property </h2
            <p id="gfg">GeeksforGeeksGeeksGeeks. 
            A computer science portal for geeks .</p
            <button onclick="myGeeks()">Submit</button>
  
                <script>
            function myGeeks() {
        document.getElementById("gfg").style.wordBreak = "normal";
                }
    </script>
        </center
    </body
</html>                    

chevron_right


output:
Before Clicking On Button:

After Clicking On Button:

Supported Browsers: The browser supported by DOM Style wordBreak Property are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.