CSS word-wrap Property

The CSS word-wrap property controls whether long words and unbroken strings can wrap onto additional lines to prevent text from overflowing its container.

The word-wrap property is the legacy name for overflow-wrap. Both properties provide the same functionality, but overflow-wrap is the preferred modern name. They are useful for handling long URLs, filenames, identifiers, and other text that contains few natural line-breaking opportunities.

Syntax

The word-wrap property accepts three keyword values that determine how otherwise unbreakable text is handled.

selector {
  word-wrap: normal | break-word | anywhere;
}

Common declarations include:

.text {
  word-wrap: normal;
}
.long-word {
  word-wrap: break-word;
}
.flexible-text {
  word-wrap: anywhere;
}

The property also accepts the CSS-wide keywords initial, inherit, unset, revert, and revert-layer.

For new stylesheets, use the equivalent overflow-wrap property when possible.

Property Values

Value Description
normal Allows lines to break only at normal line-breaking opportunities. Long unbroken strings may overflow their containers. This is the initial value.
break-word Allows an otherwise unbreakable string to break at arbitrary points when necessary to prevent overflow. These emergency breaks are not considered when calculating min-content intrinsic sizes.
anywhere Allows an otherwise unbreakable string to break at arbitrary points when necessary. Unlike break-word, these opportunities are considered during min-content sizing.
initial Resets the property to its initial value, normal.
inherit Uses the computed value of the parent element.
unset Uses the inherited value because word-wrap is an inherited property.
revert Reverts the property according to the CSS cascade.
revert-layer Reverts the property according to the previous cascade layer.

The word-wrap property does not accept length or percentage values. It controls where additional line breaks may occur rather than specifying a physical spacing measurement.

How It Works

When text reaches the available width of a container, the browser normally looks for permitted line-breaking opportunities, such as spaces between English words.

Some content contains no convenient breaking opportunities. A long URL, for example, may extend beyond the container instead of wrapping.

The word-wrap property allows the browser to introduce additional line breaks when necessary to prevent this overflow.

.content-box {
  width: 200px;
  word-wrap: break-word;
}

In this example, ordinary text wraps normally. If an unbroken string is too long to fit within the available width, the browser may divide it across multiple lines.

The property does not insert spaces, hyphens, or other characters into the underlying text. It only affects how the content is displayed.

For the additional breaking opportunities to be useful, the element must have a constrained available width and text wrapping must be permitted.

word-wrap and overflow-wrap

The word-wrap property was introduced before the standardized overflow-wrap name became established.

CSS now defines word-wrap as a legacy alias for overflow-wrap. Browsers must treat the two property names as equivalent.

.legacy-example {
  word-wrap: break-word;
}
.modern-example {
  overflow-wrap: break-word;
}

Both declarations produce the same wrapping behavior.

When maintaining older stylesheets, there is no need to remove working word-wrap declarations solely because the property has a newer name. For newly written CSS, however, overflow-wrap is recommended.

Using Both Property Names

Older projects sometimes include both declarations for compatibility.

.text-container {
  word-wrap: break-word;
  overflow-wrap: break-word;
}

Modern browsers recognize both names. The second declaration is therefore generally redundant in current browsers, but this pattern may be encountered in existing code.

Because the names are aliases, their declarations participate in the cascade as the same property. If different values are specified, normal cascade rules determine which value applies.

normal vs. break-word

The difference between normal and break-word becomes apparent when a container contains a long string without spaces.

Using normal

The normal value follows ordinary line-breaking rules.

.normal-text {
  width: 180px;
  word-wrap: normal;
}

A long unbroken word may overflow because the browser has no permitted breaking opportunity within it.

Using break-word

The break-word value allows emergency breaks when an otherwise unbreakable string would overflow.

.wrapped-text {
  width: 180px;
  word-wrap: break-word;
}

The browser first uses normal breaking opportunities. It introduces breaks within long strings only when necessary to fit the available width.

This makes break-word useful for paragraphs containing occasional long words or identifiers without unnecessarily breaking ordinary words.

anywhere vs. break-word

The anywhere and break-word values behave similarly when text must wrap inside a fixed-width container. Their important difference concerns intrinsic sizing.

Value Wrapping Behavior Min-Content Sizing
break-word Introduces emergency breaks when necessary to prevent overflow. Does not consider the additional breaking opportunities when calculating min-content size.
anywhere Introduces emergency breaks when necessary to prevent overflow. Considers the additional breaking opportunities when calculating min-content size.

Understanding Min-Content Sizing

Min-content sizing describes how narrow an element can become without overflowing its contents under the applicable line-breaking rules.

Consider a grid item containing a very long unbroken filename. With break-word, the filename may still contribute a large min-content width. With anywhere, the browser can account for additional breaks when calculating that width.

.grid-item {
  overflow-wrap: anywhere;
}

This can be especially helpful in CSS Grid and Flexbox layouts where long strings may otherwise prevent items from shrinking as expected.

Although word-wrap: anywhere is valid in modern implementations, use overflow-wrap: anywhere in new code to follow the preferred property name.

word-wrap vs. word-break

The word-wrap and word-break properties both affect line wrapping, but they serve different purposes.

Property Purpose
word-wrap Allows additional breaks in otherwise unbreakable text when necessary to prevent overflow.
word-break Controls line-breaking rules within words and character sequences, including language-specific behavior.

For example:

.emergency-wrap {
  overflow-wrap: break-word;
}
.character-breaks {
  word-break: break-all;
}

The first declaration preserves normal word-breaking opportunities and introduces additional breaks when necessary.

The second permits breaks between characters in non-CJK text, potentially splitting ordinary words at positions where normal wrapping would keep them together.

For long URLs, filenames, and identifiers, overflow-wrap is generally preferable to word-break: break-all.

Practical Uses

Long URLs

URLs may contain long sections without spaces and can overflow narrow containers.

.url-container {
  overflow-wrap: anywhere;
}

This allows the browser to break the URL across lines when necessary.

Filenames and Identifiers

Long filenames, product identifiers, and automatically generated strings can create similar problems.

.filename {
  word-wrap: break-word;
}

Wrapping allows the complete text to remain visible without requiring horizontal scrolling in many layouts.

User-Generated Content

Comments, messages, and other user-generated content may contain unexpectedly long words or repeated characters.

.comment-content {
  overflow-wrap: anywhere;
}

This is useful when the content cannot be predicted or controlled in advance.

Responsive Cards

Text inside narrow cards can overflow when it contains unbroken strings.

.card-description {
  overflow-wrap: anywhere;
}

The anywhere value can help the card fit within responsive layouts, including those that use intrinsic sizing.

Examples

Example 1: Default Wrapping

The default normal value uses ordinary line-breaking opportunities.

.example-normal {
  width: 200px;
  word-wrap: normal;
}

Long unbroken strings may extend beyond the container.

Example 2: Breaking Long Words

The break-word value allows emergency wrapping.

.example-break {
  width: 200px;
  word-wrap: break-word;
}

Long words can wrap when they would otherwise overflow.

Example 3: Using anywhere

The anywhere value allows emergency breaks and includes them in min-content sizing calculations.

.example-anywhere {
  overflow-wrap: anywhere;
}

This is especially useful when content must fit within flexible or intrinsically sized layout tracks.

Example 4: Combining with max-width

A maximum width can constrain text while allowing the container to remain flexible.

.responsive-text {
  max-width: 100%;
  overflow-wrap: anywhere;
}

The text wraps according to the available width rather than requiring a fixed pixel measurement.

Example 5: Wrapping Inside a Grid

Long content can influence the minimum width of a grid item.

.content-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.content-grid p {
  overflow-wrap: anywhere;
}

The combination of flexible grid tracks and additional breaking opportunities helps long strings fit within their columns.

Example 6: Restoring Normal Wrapping

Use normal to remove additional emergency wrapping opportunities.

.text {
  word-wrap: break-word;
}
.text.no-extra-wrap {
  word-wrap: normal;
}

When the second class is applied, the text returns to normal line-breaking behavior.

Inheritance

The word-wrap property is inherited. Child elements normally receive the computed wrapping value of their parent unless they specify a different value.

.parent {
  word-wrap: break-word;
}
.child {
  /* Inherits break-word */
}

The initial value is normal, and the property applies to text content within elements.

Because the value is inherited, applying word-wrap to a container can affect paragraphs, links, headings, and other descendant text.

Use a more specific declaration when a child element requires different wrapping behavior.

Practical Example

This example compares the default wrapping behavior with break-word and anywhere using the same long unbroken word inside narrow containers.

HTML

<div class="word-wrap-demo">
  <div class="word-wrap-example">
    <strong>word-wrap: normal</strong>
    <div class="word-wrap-box wrap-normal">
      Supercalifragilisticexpialidocious
    </div>
  </div>
  <div class="word-wrap-example">
    <strong>word-wrap: break-word</strong>
    <div class="word-wrap-box wrap-break">
      Supercalifragilisticexpialidocious
    </div>
  </div>
  <div class="word-wrap-example">
    <strong>word-wrap: anywhere</strong>
    <div class="word-wrap-box wrap-anywhere">
      Supercalifragilisticexpialidocious
    </div>
  </div>
</div>

CSS

.word-wrap-demo {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}
.word-wrap-example {
  width: 180px;
}
.word-wrap-example strong {
  display: block;
  margin-bottom: 8px;
}
.word-wrap-box {
  box-sizing: border-box;
  width: 100%;
  padding: 12px;
  border: 1px solid #ccc;
  background: #f5f5f5;
}
.wrap-normal {
  word-wrap: normal;
}
.wrap-break {
  word-wrap: break-word;
}
.wrap-anywhere {
  word-wrap: anywhere;
}
Browser Result
word-wrap: normal
Supercalifragilisticexpialidocious
word-wrap: break-word
Supercalifragilisticexpialidocious
word-wrap: anywhere
Supercalifragilisticexpialidocious

Result: The first box uses normal line-breaking rules, so the long word may overflow. The second and third boxes allow the word to wrap inside the available width.

The break-word and anywhere examples appear similar because the boxes have fixed widths. Their difference becomes important when intrinsic sizing determines an element's width, such as in certain Grid and Flexbox layouts.

Common Mistakes

Assuming word-wrap and word-break Are Identical

The properties have different purposes. The word-wrap property introduces emergency breaking opportunities, while word-break changes the rules for breaking within words and character sequences.

Using Unsupported Length Values

The word-wrap property accepts keywords rather than length values.

/* Incorrect */
.text {
  word-wrap: 10px;
}
/* Correct */
.text {
  word-wrap: break-word;
}

Expecting Wrapping with white-space: nowrap

The white-space property controls whether text is allowed to wrap. If wrapping is disabled, word-wrap cannot force ordinary line wrapping.

.text {
  white-space: nowrap;
  word-wrap: break-word;
}

In this example, the nowrap setting prevents normal wrapping. Change the white-space behavior if wrapping is required.

Ignoring Intrinsic Sizing

The break-word value does not include emergency breaking opportunities when calculating min-content sizes.

In layouts where long strings prevent an item from shrinking, consider overflow-wrap: anywhere or appropriate minimum-width constraints.

Using break-all Instead of Emergency Wrapping

The declaration word-break: break-all can split ordinary words between characters. This is often unnecessary when the goal is only to prevent long strings from overflowing.

Prefer overflow-wrap: anywhere or overflow-wrap: break-word for that purpose.

Assuming word-wrap Adds Hyphens

The word-wrap property does not automatically insert visible hyphens at emergency breaks.

Use the hyphens property when language-aware hyphenation is required.

Important Considerations

  • Legacy alias: The word-wrap property is an alias for overflow-wrap, which is the preferred modern name.
  • Readability: Emergency wrapping preserves ordinary word boundaries whenever possible.
  • Long strings: URLs, filenames, identifiers, and user-generated content commonly benefit from additional breaking opportunities.
  • Intrinsic sizing: The anywhere value includes emergency breaks in min-content sizing calculations, while break-word does not.
  • Responsive layouts: Wrapping can help text fit within narrow cards, grid tracks, and other constrained containers.
  • Inheritance: Child elements inherit the computed wrapping value unless they override it.
  • White-space behavior: Text wrapping must be permitted for emergency breaks to take effect.
  • Hyphenation: Emergency wrapping does not automatically insert hyphens.
  • Accessibility: Allow text to reflow when users enlarge text or adjust their display settings.

For new projects, use overflow-wrap rather than word-wrap. The legacy property remains useful when reading or maintaining older CSS.

Browser Support

The CSS word-wrap property is widely supported in modern browsers, including Chrome, Edge, Firefox, Safari, and Opera.

The normal and break-word values have long-standing support. The anywhere value is newer and may not be available in older browser versions.

For current compatibility information, visit Can I Use? .

Specifications

The word-wrap property is defined as a legacy alias for overflow-wrap in the CSS Text Module specifications.