The updated answer should be:
overflow-wrap:break-word;
It will break a word that by itself would not be able to fit on its own line, but leave all other words as they are (see overflow-wrap here).
You could also use:
overflow-wrap:anywhere;
but this will allow line breaks after any word in an effort to reduce the width of an element. See the difference described below from MDN:
[break-word is] The same as the anywhere value, with normally unbreakable words allowed to be broken at arbitrary points if there are no otherwise acceptable break points in the line, but soft wrap opportunities introduced by the word break are NOT considered when calculating min-content intrinsic sizes.
Also, anywhere
is not supported by Internet Explore, Safari, and some mobile browsers while break-word
is supported on all major browsers (see [here][2]).
word-break: break-word;
should no longer be used because it is deprecated in favor of the overflow-wrap:break-word;
. Now, the word-break
property is intended to be used when you want to break words regardless of whether they could fit on their own line (i.e. the OP's first example with word-break: break-all
.
In contrast to word-break, overflow-wrap will only create a break if an entire word cannot be placed on its own line without overflowing.
(From overflow-wrap also linked above )
word-break: normal; word-wrap: break-word
? (I don't use CSS above a very primitive level, or know how it's handled, but it "seems like it might work". – Kammerer