CSS propertyTypography

overflow-wrap

Breaks long words only when they would otherwise overflow their container.

Initial value
normal
Inherited
Yes
Animatable
no
Applies to
text elements
JavaScript
element.style.overflowWrap = "anywhere"
On this page

Example

#
CSS
.comment {
  overflow-wrap: anywhere;
}
Preview

Definition and usage

#

The overflow-wrap property is a safety net for long strings of characters. Unlike word-break: break-all, it leaves ordinary words untouched. It only breaks a word when it truly can’t fit on the line as a whole.

break-word and anywhere behave similarly, but anywhere also factors into the calculation of an element’s minimum width. In practice, anywhere better protects against columns getting pushed wider in flex and grid layouts.

This property used to be called word-wrap, and that name still works as an alias.

Syntax

#
Syntax
overflow-wrap: normal | break-word | anywhere;

Values

#
  • normal

    The long word overflows the box.
  • break-word

    The long word breaks, ordinary ones stay untouched.
  • anywhere

    Like break-word, but also counted toward the minimum width.

Values in practice

#

normal

The long word overflows the box.
.demo { overflow-wrap: normal; }

break-word

The long word breaks, ordinary ones stay untouched.
.demo { overflow-wrap: break-word; }

anywhere

Like break-word, but also counted toward the minimum width.
.demo { overflow-wrap: anywhere; }

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • Add overflow-wrap: anywhere to comments and user-submitted content. A single long link won’t then stretch the layout.
  • In flex containers, pair it with min-width: 0 on the element holding the text.

Related entries

#

Spotted a mistake or missing an example? Write to us.