Word-Break vs Overflow-Wrap vs Hyphens in CSS?
Handling text overflow in CSS often comes down to choosing among
word-break, overflow-wrap, and
hyphens. While all three properties prevent long strings of
text from breaking outside their container boundaries, they do so with
different logic: overflow-wrap breaks unbreakable words
only when necessary to prevent overflow, word-break
controls how words break across arbitrary lines (often breaking
aggressively), and hyphens splits words according to
language-specific dictionary rules using visible hyphen characters.
overflow-wrap (formerly word-wrap)
The overflow-wrap property specifies whether the browser
may break lines within an otherwise unbreakable string to prevent it
from overflowing its line box.
When set to overflow-wrap: break-word, the browser first
attempts to place the long word on a new line. If the word is still too
wide to fit within the container's width, the browser breaks the word at
an arbitrary point. This behavior preserves natural word boundaries
whenever possible and only splits a word as a last resort.
.container {
overflow-wrap: break-word;
/* overflow-wrap: anywhere; also available to calculate min-content sizing differently */
}word-break
The word-break property specifies soft wrap rules
between letters within text. Unlike overflow-wrap,
word-break alters the standard wrapping algorithms rather
than serving solely as an overflow safety valve.
Setting word-break: break-all allows words to break
between any two characters to fill the line completely, without
attempting to move the word to the next line first. This can create
ragged reading experiences for western languages, as standard words may
split arbitrarily mid-word even when space is available on the following
line.
.container {
word-break: break-all;
/* word-break: keep-all; prevents breaks for CJK text */
}hyphens
The hyphens property controls the hyphenation of text
across multiple lines when a word breaks. Rather than chopping text
abruptly, it uses language-aware hyphenation dictionaries to insert
hyphen marks (-) at syllable boundaries.
For hyphens: auto to work correctly, the document or
element must have an appropriate lang attribute defined
(for example, <html lang="en">).
.container {
hyphens: auto;
/* Options: none | manual | auto */
}Key Differences Summary
| Property | Primary Purpose | Break Location | Visual Indicator |
|---|---|---|---|
overflow-wrap: break-word |
Prevents container overflow | Anywhere in the word (only if it doesn't fit on a new line) | None |
word-break: break-all |
Maximizes line filling | Anywhere in the word immediately at line boundary | None |
hyphens: auto |
Improves readability of wrapped text | Syllable boundaries based on dictionary rules | Hyphen character (-) |
Choosing the Right Property
For general responsive layout safety (such as handling user-generated
content, long URLs, or unpredictable strings),
overflow-wrap: break-word is the standard choice because it
maintains normal word spacing until overflow occurs. For justified or
narrow columns of body text, hyphens: auto creates balanced
margins without awkward gaps. Use word-break: break-all
primarily when dealing with continuous non-dictionary strings where
filling available horizontal space is more critical than word
readability.