word-wrap: break-word recently changed to overflow-wrap: break-word
- will wrap long words onto the next line.
- adjusts different words so that they do not break in the middle.
word-break: break-all
- irrespective of whether it’s a continuous word or many words, breaks them up at the edge of the width limit. (i.e. even within the characters of the same word)
So if you have many fixed-size spans which get content dynamically, you might just prefer using word-wrap: break-word, as that way only the continuous words are broken in between, and in case it’s a sentence comprising many words, the spaces are adjusted to get intact words (no break within a word).
And if it doesn’t matter, go for either.
Answer from Bhumi Singhal on Stack Overflowword-wrap: break-word recently changed to overflow-wrap: break-word
- will wrap long words onto the next line.
- adjusts different words so that they do not break in the middle.
word-break: break-all
- irrespective of whether it’s a continuous word or many words, breaks them up at the edge of the width limit. (i.e. even within the characters of the same word)
So if you have many fixed-size spans which get content dynamically, you might just prefer using word-wrap: break-word, as that way only the continuous words are broken in between, and in case it’s a sentence comprising many words, the spaces are adjusted to get intact words (no break within a word).
And if it doesn’t matter, go for either.
The W3 specification that talks about these seem to suggest that word-break: break-all is for requiring a particular behaviour with CJK (Chinese, Japanese, and Korean) text, whereas word-wrap: break-word is the more general, non-CJK-aware, behaviour.
Is there a property like word-wrap or overflow-wrap that can force breaks at word boundaries?
html - Difference between word-wrap: break-word and word-break: break-word - Stack Overflow
html - Difference between overflow-wrap and word-break? - Stack Overflow
When to use CSS text-wrap: balance; vs text-wrap: pretty;
Videos
For example, If I have a sentence like the following:
I like cute dogs because they're awesome
doing something like word-break: break-word might give you
I like cute dogs because they're awe
some
The behavior I want is for it to break like
I like cute dogs because they're
awesome
I can't seem to find a way to do this. Thanks for the help and cheers.
The text is rendered inside of a container, and the width of the container typically succeeds in efficiently distributing the inner text, but not in all cases. There are weird cases of overflow, even for words whose length is only a fraction of the available width.
where needed?
Quoting from source
overflow-wrap: The overflow-wrap CSS property is used to specify whether or not the browser may break lines within words in order to prevent overflow when an otherwise unbreakable string is too long to fit in its containing box.
word-wrap: The
word-wrapproperty was renamed tooverflow-wrapin CSS3.word-break: The word-break CSS property is used to specify how (or if) to break lines within words
So, you need word-break in combination with word-wrap, which is the right combination.
It helps to understand that at this point, word-break: break-word is really an alias for overflow-wrap: anywhere.
word-break: break-word is officially deprecated; see the CSS Text Module Level 3 Working Draft:
For compatibility with legacy content, the
word-breakproperty also supports a deprecatedbreak-wordkeyword. When specified, this has the same effect asword-break: normalandoverflow-wrap: anywhere, regardless of the actual value of the overflow-wrap property.
The thing to note here is that word-break: break-word is an alias for overflow-wrap: anywhere, NOT an alias for overflow-wrap: break-word.
(word-break: normal is just the default value for word-break, so you can ignore it unless you're setting a different value for word-break.)
How do overflow-wrap: anywhere and overflow-wrap: break-word differ?
The only difference in the documentation between the two is that overflow-wrap: anywhere DOES "consider soft wrap opportunities introduced by the word break" when it is "calculating min-content intrinsic sizes", while overflow-wrap: break-word does NOT.
I guess widths might be more accurate in some cases if it is considering them?