CSS word-break Property

You are Here:

CSS word-break Property

CSS word-break property sets whether line breaks appear wherever the text would otherwise overflow its content box.

Example

HTML Online Editor
<!DOCTYPE html> <html lang="en-US"> <head> <style> div{ padding: 10px; border: 1px solid #000; font-size: 17px; width: 180px; margin-bottom: 10px; } #point{ word-break: normal; } #point1{ word-break: keep-all; } #point2{ word-break: break-all; } #point3{ word-break: break-word; } </style> </head> <body> <h1>CSS word-break Property</h1> <h2>word-break: normal;</h2> <div id="point"> This text will break to next line 这是绕道而行的好方法 WhenWordBreakBreakAllIsUsed. </div> <h2>word-break: keep-all;</h2> <div id="point1"> This text will break to next line 这是绕道而行的好方法 WhenWordBreakBreakAllIsUsed. </div> <h2>word-break: break-all;</h2> <div id="point2"> This text will break to next line 这是绕道而行的好方法 WhenWordBreakBreakAllIsUsed. </div> <h2>word-break: break-word;</h2> <div id="point3"> This text will break to next line 这是绕道而行的好方法 WhenWordBreakBreakAllIsUsed. </div> </body> </html>

Syntax

Using CSS

element{ word-break: keep-all; }

Using Javascript

object.style.wordBreak="keep-all";

Animatable

No, word-break property is not animatable. CSS Animatable Properties Reference.

Default Value

Default value for CSS word-break property is normal.

Property Value

The following table provides a list of values for CSS word-break property.

ValueExplanation
normalUse the default line break rule.
keep-allWord breaks should not be used for Chinese/Japanese/Korean (CJK) text. Non-CJK text behavior is the same as for normal.
break-allTo prevent overflow, word may be broken at any character.
break-wordTo prevent overflow, word may be broken at arbitrary points.

Using JavaScript

In the following example, we will demonstrate how to change the CSS word-break property of an element using JavaScript.

Example

HTML Online Editor
<!DOCTYPE html> <html lang="en-US"> <head> <style> div{ padding: 10px; border: 1px solid #000; font-size: 17px; width: 180px; margin-bottom: 10px; } </style> </head> <body> <h1>CSS word-break Property</h1> <div> This text will break to next line 这是绕道而行的好方法 WhenWordBreakBreakAllIsUsed. </div> <button onclick="myFunction()">Click Me</button> <script> var x = document.getElementsByTagName("div")[0]; function myFunction(){ x.style.wordBreak = "keep-all"; } </script> </body> </html>

Reminder

Hi Developers, we almost covered 98.7% of CSS Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in CSS.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author