CSS text-wrap-mode Property

The CSS text-wrap-mode property controls whether text can automatically wrap onto additional lines when it reaches the available width.

It accepts two values, wrap and nowrap. The property is a longhand component of the text-wrap shorthand and works alongside text-wrap-style, which controls how line breaks are selected when wrapping is enabled.

text-wrap-mode Syntax

The property accepts one of two keywords that determine whether ordinary soft line wrapping is permitted.

Basic Syntax

.example {
  text-wrap-mode: wrap;
}

Available Values

.example {
  text-wrap-mode: wrap;
}
.example {
  text-wrap-mode: nowrap;
}

CSS-Wide Keywords

.example {
  text-wrap-mode: initial;
}
.example {
  text-wrap-mode: inherit;
}
.example {
  text-wrap-mode: unset;
}
.example {
  text-wrap-mode: revert;
}
.example {
  text-wrap-mode: revert-layer;
}

Invalid Examples

.example {
  text-wrap-mode: normal;
}
.example {
  text-wrap-mode: balance;
}
.example {
  text-wrap-mode: pretty;
}
.example {
  text-wrap-mode: none;
}
.example {
  text-wrap-mode: 300px;
}
.example {
  text-wrap-mode: wrap nowrap;
}

The balance and pretty keywords belong to text-wrap-style, not text-wrap-mode. Lengths, percentages, and multiple wrapping-mode keywords are also invalid.

Property Values

Value Description
wrap Allows text to wrap automatically at permitted soft line-breaking opportunities.
nowrap Prevents automatic soft wrapping within the text.
initial Restores the initial value, wrap.
inherit Uses the computed value inherited from the parent element.
unset Inherits the parent's value because the property is inherited.
revert Reverts the value according to the CSS cascade.
revert-layer Reverts the value according to the previous cascade layer.

Property Characteristics

Characteristic Value
Initial value wrap
Inherited Yes
Applies to Text-containing elements
Computed value As specified
Animation type Discrete
Percentages Not accepted
Shorthand property text-wrap
Specification CSS Text Module Level 4

Note: The initial value is wrap, so ordinary text is allowed to wrap unless another CSS declaration changes the wrapping mode.

How It Works

When text is wider than the available line width, the browser determines whether it can move part of the text onto another line.

The text-wrap-mode property controls whether automatic soft line breaks are permitted.

Step 1: Create a Text Container

<p class="wrapping-text">CSS allows text to wrap naturally inside a container.</p>

Step 2: Set the Container Width

.wrapping-text {
  width: 250px;
}

Step 3: Enable Wrapping

.wrapping-text {
  width: 250px;
  text-wrap-mode: wrap;
}

Text moves onto additional lines as needed.

Step 4: Disable Wrapping

.wrapping-text {
  width: 250px;
  text-wrap-mode: nowrap;
}

Text remains on the same line at ordinary soft-wrap opportunities, potentially extending beyond the container.

Important Consideration

The property does not control the width of the container or determine the exact locations of line breaks when wrapping is enabled. Those behaviors depend on the available width and other text layout rules.

The wrap Value

The wrap value permits automatic line wrapping when text reaches the available width.

Basic Example

.example {
  text-wrap-mode: wrap;
}

HTML Example

<p class="normal-wrapping">This sentence wraps automatically when it reaches the edge of its container.</p>

CSS Example

.normal-wrapping {
  max-width: 280px;
  text-wrap-mode: wrap;
}
Browser Result

This sentence wraps automatically when it reaches the edge of its container.

Default Behavior

Because wrap is the initial value, it is normally unnecessary to specify the property for ordinary paragraphs.

Restoring Wrapping

.label {
  text-wrap-mode: nowrap;
}
.label.allow-wrapping {
  text-wrap-mode: wrap;
}

When to Use wrap

Use wrap for paragraphs, descriptions, headings, and other text that must adapt to different screen widths.

Long Unbroken Text

The wrap value does not guarantee that long URLs or unbroken strings will fit within the container. Use overflow-wrap when additional breaking opportunities are necessary.

.long-content {
  text-wrap-mode: wrap;
  overflow-wrap: anywhere;
}

The nowrap Value

The nowrap value prevents automatic soft wrapping. Text remains on the same line unless a forced line break or another applicable layout rule creates a new line.

Basic Example

.example {
  text-wrap-mode: nowrap;
}

HTML Example

<p class="no-wrapping">This sentence stays on one line even inside a narrow container.</p>

CSS Example

.no-wrapping {
  width: 280px;
  text-wrap-mode: nowrap;
}
Browser Result

This sentence stays on one line even inside a narrow container.

Button Labels

.action-button {
  text-wrap-mode: nowrap;
}

This can prevent short button labels from breaking across multiple lines.

Navigation Links

.navigation-link {
  text-wrap-mode: nowrap;
}

Table Cells

.data-table .reference-code {
  text-wrap-mode: nowrap;
}

This can be useful for short identifiers that should remain together.

Overflow Behavior

Disabling wrapping does not automatically add scrolling or hide overflowing text. Overflow must be managed separately when necessary.

When to Use nowrap

Use nowrap for short labels, identifiers, and interface elements where keeping the text together is important.

When to Avoid nowrap

Avoid applying it broadly to paragraphs, article content, or other long text that needs to reflow on narrow screens.

Soft and Forced Line Breaks

CSS distinguishes between soft line breaks, which are selected automatically, and forced line breaks, which are explicitly required by the content or layout.

Soft Line Breaks

Soft line breaks occur when text wraps because it cannot fit on the current line.

.example {
  text-wrap-mode: wrap;
}

With wrapping enabled, the browser may break text at spaces and other permitted line-breaking opportunities.

Preventing Soft Line Breaks

.example {
  text-wrap-mode: nowrap;
}

This disables ordinary automatic soft wrapping.

Forced Line Breaks

A forced line break is explicitly introduced, for example, by an HTML <br> element.

<p class="forced-break">First line<br>Second line</p>
.forced-break {
  text-wrap-mode: nowrap;
}
Browser Result

First line
Second line

The explicit line break remains even though ordinary soft wrapping is disabled.

Newline Characters

Whether newline characters in the source create visible line breaks depends on whitespace handling. For example, white-space-collapse: preserve preserves source newlines.

Important Consideration

The nowrap value should not be interpreted as a guarantee that all content will occupy exactly one line. Forced breaks can still create multiple lines.

Relationship With text-wrap

The text-wrap-mode property is one of two longhand properties controlled by the text-wrap shorthand.

The Two Longhand Properties

.example {
  text-wrap-mode: wrap;
  text-wrap-style: balance;
}

Equivalent Shorthand

.example {
  text-wrap: wrap balance;
}

Using the Shorthand for nowrap

.example {
  text-wrap: nowrap;
}

This sets text-wrap-mode to nowrap and resets text-wrap-style to auto.

Using Only the Longhand

.example {
  text-wrap-mode: nowrap;
}

This changes only the wrapping mode. It does not reset an existing text-wrap-style value.

Declaration Order

.example {
  text-wrap-mode: nowrap;
  text-wrap: balance;
}

The final shorthand sets the wrapping mode back to wrap and applies the balance style.

Reversing the Order

.example {
  text-wrap: balance;
  text-wrap-mode: nowrap;
}

The final longhand disables soft wrapping while retaining the previously specified balance style. That style has no practical balancing effect while soft wrapping is disabled.

When to Use the Longhand

Use text-wrap-mode when only the wrapping mode needs to change without resetting the wrapping style.

Relationship With white-space

The white-space property is another shorthand that affects text wrapping. It also controls how whitespace is collapsed or preserved.

Traditional Syntax

.example {
  white-space: nowrap;
}

Modern Longhand Syntax

.example {
  text-wrap-mode: nowrap;
}

Both declarations disable ordinary soft wrapping, but the longhand focuses specifically on wrapping mode.

Whitespace Collapsing

.example {
  white-space-collapse: collapse;
  text-wrap-mode: wrap;
}

The first property controls whitespace collapsing, while the second controls whether soft wrapping is permitted.

Preserved Whitespace

.example {
  white-space-collapse: preserve;
  text-wrap-mode: wrap;
}

This preserves whitespace while allowing soft wrapping where the applicable line-breaking rules permit it.

Comparison

Property Purpose
white-space Controls whitespace collapsing and wrapping as a shorthand.
white-space-collapse Controls how whitespace is collapsed or preserved.
text-wrap-mode Controls whether ordinary soft wrapping is permitted.

Declaration Order

Because white-space can set the wrapping mode, a later white-space declaration may override an earlier text-wrap-mode declaration when both have equal cascade priority.

.example {
  text-wrap-mode: wrap;
  white-space: nowrap;
}

In this example, the later shorthand disables soft wrapping.

Text Wrapping and Overflow

Disabling wrapping can cause text to extend beyond its container. The text-wrap-mode property does not control how that overflow is displayed.

Text Overflowing a Container

.example {
  width: 250px;
  text-wrap-mode: nowrap;
}

Long text may extend beyond the element's available width.

Horizontal Scrolling

.scrolling-text {
  max-width: 300px;
  overflow-x: auto;
  text-wrap-mode: nowrap;
}

Clipping Overflow

.clipped-text {
  width: 250px;
  overflow: hidden;
  text-wrap-mode: nowrap;
}

This hides content that extends beyond the container.

Single-Line Ellipsis

.ellipsis-text {
  width: 250px;
  overflow: hidden;
  text-overflow: ellipsis;
  text-wrap-mode: nowrap;
}

The browser can display an ellipsis when overflowing inline text is clipped, subject to the applicable text-overflow rules.

Allowing Long Words to Break

.long-text {
  text-wrap-mode: wrap;
  overflow-wrap: anywhere;
}

This allows long unbroken strings to wrap when necessary.

Important Consideration

Clipping or truncating text can hide important information. Use these techniques only when the complete content remains accessible through an appropriate interface.

Several CSS properties work with text-wrap-mode to control text wrapping and overflow.

text-wrap

.example {
  text-wrap: balance;
}

Controls wrapping mode and line-breaking style through a shorthand.

text-wrap-style

.example {
  text-wrap-style: pretty;
}

Controls the browser's line-breaking strategy when wrapping is enabled.

overflow-wrap

.example {
  overflow-wrap: anywhere;
}

Allows additional breaks in otherwise unbreakable text.

word-break

.example {
  word-break: break-all;
}

Controls opportunities for breaking words.

hyphens

.example {
  hyphens: auto;
}

Allows automatic hyphenation where supported and appropriate.

white-space

.example {
  white-space: pre-wrap;
}

Controls whitespace handling and wrapping behavior.

text-overflow

.example {
  text-overflow: ellipsis;
}

Controls how clipped inline text overflow is indicated.

overflow-x

.example {
  overflow-x: auto;
}

Controls horizontal overflow behavior.

Complete Example

.text-container {
  max-width: 320px;
  text-wrap-mode: wrap;
  overflow-wrap: anywhere;
  line-height: 1.6;
}

Inheritance

The text-wrap-mode property is inherited. Descendant elements use the parent's computed value unless another declaration overrides it.

Parent Element Example

.content {
  text-wrap-mode: nowrap;
}

Child Element Override

.content {
  text-wrap-mode: nowrap;
}
.content p {
  text-wrap-mode: wrap;
}

Paragraphs can wrap normally even when the parent has disabled soft wrapping.

Explicit Inheritance

.child {
  text-wrap-mode: inherit;
}

Restore the Initial Value

.child {
  text-wrap-mode: initial;
}

This restores wrap.

Using unset

.child {
  text-wrap-mode: unset;
}

Because the property is inherited, unset uses the parent's computed value.

Nested HTML Example

<div class="text-container">
  <p>This paragraph can wrap normally.</p>
  <span class="short-label">Short Label</span>
</div>
.text-container {
  text-wrap-mode: wrap;
}
.text-container .short-label {
  text-wrap-mode: nowrap;
}

Important Consideration

Inherited nowrap settings can cause unexpected overflow in nested content. Apply wrapping restrictions to specific elements rather than large containers when possible.

Practical Examples

Normal Paragraph Wrapping

.article-paragraph {
  max-width: 65ch;
  text-wrap-mode: wrap;
}

Prevent Button Labels From Wrapping

.action-button {
  text-wrap-mode: nowrap;
}

Navigation Menu Labels

.navigation-menu a {
  text-wrap-mode: nowrap;
}

Responsive Card Descriptions

.card-description {
  text-wrap-mode: wrap;
  overflow-wrap: break-word;
}

Single-Line File Names

.file-name {
  max-width: 250px;
  overflow: hidden;
  text-overflow: ellipsis;
  text-wrap-mode: nowrap;
}

Horizontal Scrolling for Code

.code-example {
  max-width: 100%;
  overflow-x: auto;
  text-wrap-mode: nowrap;
}

Wrapping Long URLs

.url-text {
  text-wrap-mode: wrap;
  overflow-wrap: anywhere;
}

Responsive Heading

.responsive-heading {
  text-wrap-mode: wrap;
  text-wrap-style: balance;
}

Table Identifiers

.data-table .item-id {
  text-wrap-mode: nowrap;
}

Allow Wrapping on Smaller Screens

.navigation-label {
  text-wrap-mode: nowrap;
}
@media (max-width: 600px) {
  .navigation-label {
    text-wrap-mode: wrap;
  }
}

Preserve Whitespace and Allow Wrapping

.formatted-text {
  white-space-collapse: preserve;
  text-wrap-mode: wrap;
}

Editable Text Area

.editable-content {
  text-wrap-mode: wrap;
  text-wrap-style: stable;
}

text-wrap-mode Example

This example compares the wrap and nowrap values using identical text inside containers with the same width.

HTML Example

<div class="text-wrap-mode-demo">
  <div class="wrap-sample">
    <strong>text-wrap-mode: wrap;</strong>
    <p class="wrap-enabled">Learn how CSS controls text wrapping inside responsive layouts.</p>
  </div>
  <div class="wrap-sample">
    <strong>text-wrap-mode: nowrap;</strong>
    <p class="wrap-disabled">Learn how CSS controls text wrapping inside responsive layouts.</p>
  </div>
</div>

CSS Example

.text-wrap-mode-demo {
  display: grid;
  gap: 16px;
}
.text-wrap-mode-demo .wrap-sample {
  max-width: 300px;
  padding: 16px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  overflow-x: auto;
}
.text-wrap-mode-demo strong {
  display: block;
  margin-bottom: 12px;
  color: #334155;
  font-size: 14px;
}
.text-wrap-mode-demo p {
  width: 240px;
  margin: 0;
  color: #1f2937;
  font-size: 19px;
  line-height: 1.5;
}
.text-wrap-mode-demo .wrap-enabled {
  text-wrap-mode: wrap;
}
.text-wrap-mode-demo .wrap-disabled {
  text-wrap-mode: nowrap;
}
Browser Result
text-wrap-mode: wrap;

Learn how CSS controls text wrapping inside responsive layouts.

text-wrap-mode: nowrap;

Learn how CSS controls text wrapping inside responsive layouts.

Understanding the Results

The first sample allows text to wrap onto multiple lines. The second prevents ordinary soft wrapping, so the text extends beyond its specified width.

Overflow Handling

The demonstration containers allow horizontal scrolling so that the unwrapped text remains accessible rather than being clipped.

Experiment With Width

.text-wrap-mode-demo p {
  width: 180px;
}

Reducing the width causes the wrapped sample to use more lines, while the unwrapped sample remains on one line.

Try the Shorthand

.text-wrap-mode-demo .wrap-disabled {
  text-wrap: nowrap;
}

The shorthand produces the same wrapping-mode behavior but also resets the wrapping-style longhand.

Accessibility Considerations

Allowing text to reflow is important for responsive design and accessibility, particularly when users enlarge text or view content on narrow screens.

Support Text Reflow

Long text should normally use wrap so that it can adapt to the available width.

Avoid Horizontal Scrolling for Paragraphs

Disabling wrapping on large blocks of text can force users to scroll horizontally to read each line.

Keep Labels Readable

Use nowrap selectively for short labels and controls when keeping the text together improves usability.

Test Text Enlargement

Verify that text remains readable at increased font sizes and browser zoom levels.

Avoid Hidden Content

When combining nowrap with overflow: hidden, ensure that important information is not permanently inaccessible.

Use Appropriate Line Lengths

.article-content {
  max-width: 65ch;
  line-height: 1.6;
  text-wrap-mode: wrap;
}

Handle Long Strings

Long URLs, identifiers, and other unbroken strings may require overflow-wrap to avoid overflow.

Preserve Semantic Structure

Use HTML paragraphs, headings, and lists to express document structure rather than relying on visual line breaks.

Test Responsive Layouts

Check how wrapped and unwrapped text behaves across different viewport widths, fonts, and languages.

Common Mistakes

Using normal Instead of wrap

.example {
  text-wrap-mode: normal;
}

The normal keyword is invalid. Use wrap.

Using balance as a Wrapping Mode

.example {
  text-wrap-mode: balance;
}

The balance keyword belongs to text-wrap-style.

Using pretty as a Wrapping Mode

.example {
  text-wrap-mode: pretty;
}

Use text-wrap-style: pretty or the text-wrap shorthand instead.

Using none Instead of nowrap

.example {
  text-wrap-mode: none;
}

The correct keyword is nowrap.

Using a Length Value

.example {
  text-wrap-mode: 250px;
}

Use width or max-width to control container dimensions.

Combining wrap and nowrap

.example {
  text-wrap-mode: wrap nowrap;
}

Only one wrapping-mode keyword is permitted.

Expecting nowrap to Remove Forced Breaks

Explicit breaks, such as HTML <br> elements, can still create new lines.

Expecting wrap to Break Every Long String

Some unbroken strings require additional breaking rules, such as overflow-wrap: anywhere.

Using nowrap on Long Paragraphs

This can create unnecessary horizontal overflow.

Confusing Wrapping With Overflow

The property controls soft wrapping, not whether overflow is clipped, scrolled, or displayed.

Ignoring Inheritance

A parent element with nowrap can cause unexpected behavior in its descendants.

Forgetting Shorthand Interactions

Later text-wrap or white-space shorthand declarations may override an earlier wrapping-mode declaration.

Assuming nowrap Guarantees One Line

Forced line breaks can still produce multiple lines.

Important Considerations

Keep the following points in mind when using text-wrap-mode:

  • The property controls whether automatic soft line wrapping is permitted.
  • It accepts wrap and nowrap.
  • The initial value is wrap.
  • The property is inherited.
  • It is a longhand component of the text-wrap shorthand.
  • The wrap value allows ordinary soft wrapping.
  • The nowrap value prevents ordinary soft wrapping.
  • Forced line breaks can remain effective when wrapping is disabled.
  • The property does not control container width.
  • The property does not control text alignment.
  • The property does not directly control overflow handling.
  • Unwrapped text may extend beyond its container.
  • Use overflow-x when horizontal scrolling is appropriate.
  • Use text-overflow to indicate clipped inline text where appropriate.
  • Use overflow-wrap for long unbroken strings.
  • Use text-wrap-style for balancing and other line-breaking strategies.
  • Shorthand declarations can override wrapping-mode settings.
  • Use nowrap selectively for short interface labels.
  • Allow paragraphs and long descriptions to reflow.
  • Test layouts at different screen widths and zoom levels.
  • Check inherited wrapping settings when nested content overflows unexpectedly.
  • Use semantic HTML for meaningful document structure.

Browser Support

The CSS text-wrap-mode property is supported in modern browsers. The wrap and nowrap behaviors have long been available through the white-space property, although support for the separate text-wrap-mode longhand was introduced more recently.

For current compatibility information, visit Can I Use? and search for text-wrap-mode.

Basic Declaration

.example {
  text-wrap-mode: nowrap;
}

Feature Detection

@supports (text-wrap-mode: nowrap) {
  .navigation-label {
    text-wrap-mode: nowrap;
  }
}

Fallback for Older Browsers

.navigation-label {
  white-space: nowrap;
  text-wrap-mode: nowrap;
}

The older white-space declaration provides compatible behavior in browsers that do not recognize the separate longhand.

Restoring Wrapping

.article-text {
  white-space: normal;
  text-wrap-mode: wrap;
}

Testing Recommendations

Test the property with the actual text, container widths, and browser versions used by the website. Pay particular attention to overflow when wrapping is disabled.

Specifications

The text-wrap-mode property is defined in the CSS Text Module Level 4 specification.

CSS Text Module Level 4 - text-wrap-mode Property

The specification defines the wrap and nowrap values and their relationship to soft line wrapping and the text-wrap shorthand.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: text-wrap-mode