The HTML DOM style wordBreak property returns and modify line breaking rules for non - Chinese, Japanese and Korean scripts in an HTML document.
Syntax
Following is the syntax −
Returning wordBreak
object.style.wordBreak
Modifying wordBreak
object.style.wordBreak = “value”
Values
Here, value can be −
Value | Explanation |
---|---|
initial | It set this property value to its default value. |
inherit | It inherits this property value from its parent element. |
normal | It breaks words according to their usual rules. |
keep-all | In it line breaks are disallowed between pairs of letters. |
break-all | In it lines may break between any two letters. |
Example
Let us see an example of HTML DOM style wordBreak property −
<!DOCTYPE html> <html> <head> <style> body { color: #000; background: lightblue; height: 100vh; } p { border: 2px solid #fff; width: 120px; } .btn { background: #db133a; border: none; height: 2rem; border-radius: 2px; width: 40%; display: block; color: #fff; outline: none; cursor: pointer; margin: 1rem 0; } </style> </head> <body> <h1>DOM Style wordBreak Property Example</h1> <p>Thisisaparagraphelement.</p> <button onclick="add()" class="btn">Set wordBreak</button> <script> function add() { document.querySelector('p').style.wordBreak = "break-all" } </script> </body> </html>
Output
This will produce the following output −
Click on “Set wordBreak” button to break the long word inside the paragraph element −