The word-break
property determines if and how to break lines in the middle of words.
Normally, lines that don’t fit inside their container break in certain points, specifically where there’s a white space or a hyphen. But when the word-break
property is set to break-all
, the browser will break lines at any point, even in the middle of a word that comes at the end of the line and that would be too long to fit inside the container.
The result of breaking lines in the middle of words will be close to that which we get when we justify text inside an element (see text-align
), except that white space is not affected, so there may be lines where a white space would be existent between the last word on the line and the edge of the container.
Trivia & Notes
The words broken at the end of each line by the word-break
property become practically unreadable because there is no visual indication as to where the word has been broken.
A more readable and responsive alternative would be to use the word-wrap
property in conjunction with the hyphens
property to break long words and have the browser add hyphens at the points where the words have been broken. You can take it a step further and align the text using text-align: justify
to get a full-width line effect with lines breaking words without sacrificing readability. You can read more and see more examples in the word-wrap
and hyphens
entry pages.
Official Syntax
-
Syntax:
word-break: normal | break-all | keep-all
- Initial: normal
- Applies To: all elements
- Animatable: no
Values
- normal
- Lines break according to their usual rules.
- break-all
-
In addition to
normal
breaking rules, lines may break between any two letters (except where forbidden by theline-break
property). Hyphenation is not applied.
This option is used mostly in a context where the text is predominantly using CJK characters with few non-CJK excerpts and it is desired that the text be better distributed on each line. - keep-all
-
Normal word breaks are suppressed in all characters including CJK languages. For non-CJK text, it is the same as the
normal
value.
Examples
The following line will tell the browser to break lines in the middle of words when necessary to fit inside their container.
p { word-break: break-all; }
The following line will prevent h1
elements from being broken in the middle of words:
h1 { break-word: none; }
Live Demo
View this demo on the Codrops PlaygroundBrowser Support
CSS3 word-break
Property to prevent or allow words to be broken over multiple lines between letters.
W3C Candidate Recommendation
Supported from the following versions:
Desktop
- 44
- 15
- 5.5
- 31
- 9
Mobile / Tablet
- 9.0
- 131
- No
- 131
- 132