CSS Reference Β· Typography
The word-break property
Reference for the CSS word-break property: normal, break-all, keep-all and the deprecated break-word, with live examples, usage notes and browser support.
The word-break property decides whether the browser may break a line inside a word. By default, lines wrap at spaces and hyphens, and a long unbroken string such as a URL or hash sticks out of its box. Setting word-break: break-all allows a break between any two letters, so the string wraps at the edge of the box.
The property also matters for Chinese, Japanese and Korean (CJK) text, where the default rules allow a break between almost any two characters. keep-all turns that off, so lines break only at spaces and punctuation, like in English.
.hash { word-break: break-all; }
Try it
Notice that break-all also splits ordinary words such as "shipped" at the end of a line, even though they would fit on the next line. That is why it is a tool for specific strings, not for body text.
The first box may split a Korean word between syllables. The second (keep-all) wraps only at the spaces, so every word stays whole. If your system has no Korean font you will see placeholder glyphs, but the line breaks still show the difference.
Syntax
word-break: normal | break-all | keep-all | break-word;
| Initial value | normal |
| Applies to | all elements |
| Inherited | yes |
| Animatable | no |
| Computed value | as specified |
Values
| Value | Description |
|---|---|
normal |
Default line-breaking rules for the script: breaks at spaces and hyphens in Latin text, between characters in CJK text. |
break-all |
Allows a break between any two characters in non-CJK text, with no hyphen added. CJK text behaves as normal. |
keep-all |
Forbids breaks between characters in CJK text. Non-CJK text behaves as normal. |
break-word |
Deprecated. Behaves like word-break: normal combined with overflow-wrap: anywhere. Use overflow-wrap instead. |
Some browsers are also adding an auto-phrase value that breaks Japanese text at phrase boundaries. It is new, so check a compatibility table before using it.
Usage notes
- Prefer
overflow-wrapfor long strings in prose.overflow-wrap: anywherebreaks a word only when it would not fit on a line by itself, so normal words stay intact.break-allbreaks eagerly, which hurts readability. - Good fits for
break-all: hashes, tokens, file paths and URLs in narrow table cells, or monospace code blocks where a clean edge matters more than word shapes. keep-alland long CJK strings. Withkeep-all, a long run of CJK characters without spaces cannot wrap and may overflow. Pair it withoverflow-wrapif the text is user-supplied.- No hyphens. None of the values add a hyphen. Use
hyphensif you want real hyphenation of long words. - Inheritance. The value is inherited, so setting it on a container affects all text inside.
- Flex and grid items. A long word in a flex item can also be stopped by
min-width: auto; if breaking does not seem to work, check that the item is allowed to shrink (min-width: 0).
Browser support
normal, break-all and keep-all work in all current browsers; break-word is still accepted for legacy reasons, but newer values such as auto-phrase need a check against a compatibility table.
Related
overflow-wrapβ break only when a word would overflowhyphensβ automatic or manual hyphenationwhite-spaceβ whether text wraps at allline-breakβ strictness of line-breaking rules- Lesson: Wrapping, Overflow and Hyphens