Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Box Model and Sizing

The overflow-wrap property

Reference for the CSS overflow-wrap property: when a long word or URL may be broken so it does not overflow its box. Values, anywhere vs break-word, examples.

The overflow-wrap property lets the browser break a line in the middle of a word when that word is too long to fit in its box. Without it, a long URL or an unbroken string such as a file hash pushes out of the container and causes horizontal overflow.

CSS
.comment {
  overflow-wrap: break-word;
}

The older name word-wrap is a legacy alias for the same property.

Try it

Taming a long word

The first box lets the address stick out through its right border. The second breaks the address at the box edge, only because it could not fit on a line of its own.

Syntax

CSS
overflow-wrap: normal | break-word | anywhere
  • Initial value: normal
  • Applies to: text (all elements)
  • Inherited: yes
  • Animatable: no (discrete)
  • Computed value: as specified

Values

Value Description
normal Lines break only at normal break opportunities (spaces, hyphens). A long word overflows.
break-word An otherwise unbreakable word may be broken at an arbitrary point, but only if it would overflow the line on its own.
anywhere Like break-word, but the break opportunities also count when the browser calculates the minimum content size of the box.

Usage notes

  • break-word vs anywhere. The visible result in a normally sized box is the same. The difference appears in shrink-to-fit contexts (flex items, grid tracks with auto, table cells): with anywhere the box's minimum width can shrink down to a single character, while break-word still reports the full word width, so the box may stay wide.
  • Flex and grid items. If a long word still overflows a flex item, the cause is usually min-width: auto. Add min-width: 0 to the item, or use overflow-wrap: anywhere.
  • Compared with word-break. word-break: break-all breaks anywhere even when the word would fit on the next line. overflow-wrap only breaks when it must, which looks more natural.
  • Hyphenation is separate. overflow-wrap never inserts a hyphen. Use hyphens for dictionary-based hyphenation.
  • Good defaults. Setting overflow-wrap: break-word on user-generated content (comments, chat, table cells) is a cheap way to protect a layout.

Browser support

break-word is supported everywhere; anywhere is also supported in current versions of all major browsers.