overflow-wrap – CSS: Cascading Style Sheets

The overflow-wrap CSS property applies to inline elements, setting whether the browser should insert line breaks within an otherwise unbreakable string to prevent text from overflowing its line box.

Note: 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.

The property was originally a nonstandard and unprefixed Microsoft extension called word-wrap, and was implemented by most browsers with the same name. It has since been renamed to overflow-wrap, with word-wrap being an alias.

overflow-wrap: normal; overflow-wrap: break-word; overflow-wrap: anywhere; overflow-wrap: inherit; overflow-wrap: initial; overflow-wrap: revert; overflow-wrap: unset;

The overflow-wrap property is specified as a single keyword chosen from the list of values below.

Values

normal Lines may only break at normal word break points (such as a space between two words). anywhere To prevent overflow, an otherwise unbreakable string of characters — like a long word or URL — may be broken at any point if there are no otherwise-acceptable break points in the line. No hyphenation character is inserted at the break point. Soft wrap opportunities introduced by the word break are considered when calculating min-content intrinsic sizes. break-word 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. normal | break-word | anywhere

Comparing overflow-wrap, word-break, and hyphens

This example compares the results of overflow-wrap, word-break, and hyphens when breaking up a long word.

HTML

They say the fishing is excellent at Lake Chargoggagoggmanchauggagoggchaubunagungamaugg, though I’ve never been there myself. (normal)

They say the fishing is excellent at Lake Chargoggagoggmanchauggagoggchaubunagungamaugg, though I’ve never been there myself. (overflow-wrap: anywhere)

They say the fishing is excellent at Lake Chargoggagoggmanchauggagoggchaubunagungamaugg, though I’ve never been there myself. (overflow-wrap: break-word)

They say the fishing is excellent at Lake Chargoggagoggmanchauggagoggchaubunagungamaugg, though I’ve never been there myself. (word-break)

They say the fishing is excellent at Lake Chargoggagoggmanchauggagoggchaubunagungamaugg, though I’ve never been there myself. (hyphens, without lang attribute)

They say the fishing is excellent at Lake Chargoggagoggmanchauggagoggchaubunagungamaugg, though I’ve never been there myself. (hyphens, English rules)

They say the fishing is excellent at Lake Chargoggagoggmanchauggagoggchaubunagungamaugg, though I’ve never been there myself. (hyphens, German rules)

CSS

p { width: 13em; margin: 2px; background: gold; } .ow-anywhere { overflow-wrap: anywhere; } .ow-break-word { overflow-wrap: break-word; } .word-break { word-break: break-all; } .hyphens { hyphens: auto; }

Result

BCD tables only load in the browser

Source

Leave a comment

Your email address will not be published. Required fields are marked *