CSS propertyTypography
word-break
Lets words break at any point when they don’t fit on a line.
- Initial value
normal- Inherited
- Yes
- Animatable
- no
- Applies to
- all elements
- JavaScript
element.style.wordBreak = "break-all"
Example
#CSS
.token {
word-break: break-all;
font-family: monospace;
}Example HTML
<p class="stage" style="margin: 0; width: 240px;">Your key: <code class="token" style="word-break: break-all;">cw_live_4f9a2b7c1e8d3f6a0b5c9e2d7f1a4b8c</code></p>Preview
Definition and usage
#The word-break property determines where a line is allowed to break inside words. By default, in languages like English, lines only break at spaces and hyphens, so a very long string of characters can overflow its container.
break-all lets a word break between any two characters. This works well for long URLs, identifiers, and strings with no spaces, but it also breaks ordinary words in unexpected places.
In most cases overflow-wrap: anywhere is the better choice, since it only breaks a word when it truly doesn’t fit.
Syntax
#Syntax
word-break: normal | break-all | keep-all;Values
#Values in practice
#normal
Breaking only at spaces. A long address overflows the box.
.demo { word-break: normal; }break-all
Breaking at any point, including inside ordinary words.
.demo { word-break: break-all; }keep-all
For Chinese, Japanese, and Korean text: don’t break between characters.
.demo { word-break: keep-all; }Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- For long addresses in text,
overflow-wrap: anywhereis usually enough, and it doesn’t break ordinary words. - Keys, tokens, and hashes in code are a good place for
break-all.
Related entries
#Spotted a mistake or missing an example? Write to us.