CSS text-wrap-style Property

The CSS text-wrap-style property controls how the browser chooses line breaks when text wraps onto multiple lines.

It can balance the lengths of heading lines, improve paragraph endings, or keep line breaks more stable during text editing. The property is a longhand component of the text-wrap shorthand and works alongside text-wrap-mode, which determines whether automatic wrapping is permitted.

text-wrap-style Syntax

The property accepts a single keyword that specifies the preferred line-breaking strategy.

Basic Syntax

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

Available Values

.example {
  text-wrap-style: auto;
}
.example {
  text-wrap-style: balance;
}
.example {
  text-wrap-style: pretty;
}
.example {
  text-wrap-style: stable;
}
.example {
  text-wrap-style: avoid-orphans;
}

The avoid-orphans value is a newer addition to the CSS Text specification and may not be recognized by all browsers.

CSS-Wide Keywords

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

Invalid Examples

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

The wrap and nowrap keywords belong to text-wrap-mode. Only one wrapping-style keyword can be specified at a time.

Property Values

Value Description
auto Uses the browser's normal line-breaking strategy.
balance Attempts to make the lengths of wrapped lines more balanced.
pretty Favors higher-quality line breaks, potentially reducing undesirable short final lines and other awkward breaks.
stable Uses line-breaking behavior intended to reduce changes to earlier lines while text is edited.
avoid-orphans Requests line breaking that avoids very short final lines. Support is limited.
initial Restores the initial value, auto.
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 auto
Inherited Yes
Computed value As specified
Applies to Text-containing elements
Animation type Discrete
Percentages Not accepted
Shorthand property text-wrap
Specification CSS Text Module Level 4

Note: The initial value is auto, which uses the browser's normal line-breaking behavior. Advanced values can influence line breaks but do not guarantee identical results across browsers.

How It Works

When text wraps inside a container, the browser must decide where to place line breaks. The text-wrap-style property influences those decisions.

Step 1: Create a Text Container

<h2 class="example-heading">Create Better Looking Headings With CSS</h2>

Step 2: Set a Width

.example-heading {
  max-width: 320px;
}

The available width determines how much text fits on each line.

Step 3: Apply a Wrapping Style

.example-heading {
  max-width: 320px;
  text-wrap-style: balance;
}

The browser attempts to distribute the text more evenly across lines.

Step 4: Try Another Style

.example-heading {
  max-width: 320px;
  text-wrap-style: pretty;
}

The browser favors improved line-breaking quality rather than specifically balancing the line lengths.

Important Consideration

The property influences line-breaking decisions only when wrapping is permitted. If text-wrap-mode is set to nowrap, there are no ordinary soft line breaks for the wrapping style to optimize.

The auto Value

The auto value uses the browser's normal line-breaking strategy.

Basic Example

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

HTML Example

<p class="normal-text">Browsers normally wrap text according to the available width and permitted line-breaking opportunities.</p>

CSS Example

.normal-text {
  max-width: 300px;
  text-wrap-style: auto;
}
Browser Result

Browsers normally wrap text according to the available width and permitted line-breaking opportunities.

Default Behavior

Because auto is the initial value, it is usually unnecessary to specify it for ordinary text.

Restoring Normal Line Breaking

.heading {
  text-wrap-style: balance;
}
.heading.normal {
  text-wrap-style: auto;
}

When to Use auto

Use auto when no special line-breaking optimization is needed or when overriding a previously applied wrapping style.

The balance Value

The balance value attempts to make wrapped lines more equal in length.

It is especially useful for short headings, titles, quotations, and other compact blocks of text.

Basic Example

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

HTML Example

<h2 class="balanced-heading">Create Better Looking Headings With Modern CSS</h2>

CSS Example

.balanced-heading {
  max-width: 340px;
  text-wrap-style: balance;
}

Comparison With auto

Browser Result

auto

Create Better Looking Headings With Modern CSS

balance

Create Better Looking Headings With Modern CSS

How Balancing Works

The browser considers alternative line breaks and attempts to reduce differences in line lengths.

Line Count Limits

Browsers may limit balancing to a certain number of lines. The value is intended primarily for relatively short text blocks rather than long paragraphs.

Performance Considerations

Balancing requires additional layout calculations, so browsers may limit how much text they process.

When to Use balance

Use balance for page headings, card titles, short quotations, and other text where evenly distributed lines improve the appearance.

The pretty Value

The pretty value favors higher-quality line breaks, potentially avoiding undesirable short final lines and other awkward wrapping.

Basic Example

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

HTML Example

<p class="pretty-paragraph">Thoughtful line wrapping can improve the appearance of paragraphs and make longer passages easier to read.</p>

CSS Example

.pretty-paragraph {
  max-width: 420px;
  text-wrap-style: pretty;
}

Short Final Lines

A very short final line is sometimes called a typographic orphan. The pretty value can help reduce these endings when suitable line-breaking opportunities are available.

Comparison With balance

Value Primary Goal
balance Make wrapped lines more similar in length.
pretty Improve overall line-breaking quality.

Browser Differences

The exact algorithm used for pretty wrapping may vary between browsers. Some browsers may produce the same line breaks as auto for a particular text block.

When to Use pretty

Use pretty for article introductions, paragraphs, descriptions, and other text where polished line endings are desirable.

Important Consideration

The property does not guarantee that every paragraph will avoid short final lines. Results depend on the text, width, font, and browser implementation.

The stable Value

The stable value is intended to keep earlier line breaks relatively stable while text is being edited.

Basic Example

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

HTML Example

<div class="editable-text" contenteditable="true">Edit this sentence and observe how the text wraps while typing.</div>

CSS Example

.editable-text {
  max-width: 360px;
  padding: 12px;
  border: 1px solid #cbd5e1;
  text-wrap-style: stable;
}

Editable Content

Stable wrapping can be useful in content editors and text composition interfaces where unexpected changes to earlier lines may be distracting.

How Stable Wrapping Works

While editing, the browser attempts to preserve earlier line breaks rather than repeatedly optimizing the entire text block.

When to Use stable

Use stable for editable content, writing interfaces, and other applications where predictable wrapping during text entry is desirable.

Important Consideration

Stable wrapping does not prevent all line changes. Editing earlier text, changing fonts, or resizing the container can still alter the layout.

The avoid-orphans Value

The avoid-orphans value requests line breaking that avoids leaving a very short final line.

It is a newer value in the CSS Text specification and has limited browser support. Use it as a progressive enhancement.

Basic Example

.example {
  text-wrap-style: avoid-orphans;
}

Paragraph Example

.article-introduction {
  max-width: 500px;
  text-wrap-style: avoid-orphans;
}

Fallback Example

.article-introduction {
  text-wrap-style: pretty;
}
@supports (text-wrap-style: avoid-orphans) {
  .article-introduction {
    text-wrap-style: avoid-orphans;
  }
}

Comparison With pretty

The pretty value requests general improvements to line-breaking quality, while avoid-orphans focuses more specifically on avoiding undesirable short final lines.

When to Use avoid-orphans

Consider this value for editorial layouts where short final lines are undesirable and the target browsers support the feature.

Important Consideration

Because support is limited, provide a suitable fallback and test the actual rendering in supported browsers.

Relationship With text-wrap

The text-wrap-style property is one of two longhand components of 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 Only the Style Keyword

.example {
  text-wrap: balance;
}

The shorthand sets text-wrap-style to balance and resets text-wrap-mode to its initial value of wrap.

Using Only the Longhand

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

This changes only the wrapping style without resetting the existing wrapping mode.

Shorthand Reset Behavior

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

The final shorthand sets text-wrap-mode to nowrap and resets text-wrap-style to auto.

Declaration Order

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

The final longhand changes the wrapping style to pretty while leaving the wrapping mode set to wrap.

When to Use the Longhand

Use text-wrap-style when only the line-breaking strategy needs to change without affecting whether text is allowed to wrap.

Relationship With text-wrap-mode

The text-wrap-mode and text-wrap-style properties control different aspects of text wrapping.

Wrapping Mode

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

Determines whether ordinary soft line wrapping is permitted.

Wrapping Style

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

Determines how the browser chooses line breaks when wrapping is permitted.

Using Both Properties

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

Disabling Wrapping

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

The wrapping style remains specified, but balancing has no practical effect when ordinary soft wrapping is disabled.

Comparison

Property Purpose
text-wrap-mode Controls whether text may wrap automatically.
text-wrap-style Controls how line breaks are chosen.
text-wrap Sets both properties through a shorthand.

Several CSS properties work with text-wrap-style to control text layout and line breaking.

text-wrap

.example {
  text-wrap: balance;
}

Controls wrapping mode and style through a shorthand.

text-wrap-mode

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

Controls whether ordinary soft wrapping is permitted.

white-space

.example {
  white-space: normal;
}

Controls whitespace collapsing and wrapping behavior.

overflow-wrap

.example {
  overflow-wrap: anywhere;
}

Allows additional breaks in otherwise unbreakable text.

word-break

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

Controls additional word-breaking opportunities.

hyphens

.example {
  hyphens: auto;
}

Allows automatic hyphenation where supported and appropriate.

line-height

.example {
  line-height: 1.6;
}

Controls line spacing rather than line-breaking locations.

max-width

.example {
  max-width: 65ch;
}

Limits the width of a text block and influences where wrapping occurs.

Complete Example

.article-text {
  max-width: 65ch;
  line-height: 1.6;
  overflow-wrap: break-word;
  text-wrap-mode: wrap;
  text-wrap-style: pretty;
}

Inheritance

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

Parent Element Example

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

Child Element Override

.content {
  text-wrap-style: pretty;
}
.content h2 {
  text-wrap-style: balance;
}

Paragraphs can use pretty wrapping while headings use balanced wrapping.

Explicit Inheritance

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

Restore the Initial Value

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

This restores auto.

Using unset

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

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

Nested HTML Example

<div class="article-content">
  <h2>Understanding CSS Text Wrapping</h2>
  <p>CSS provides several ways to improve text layout and line-breaking behavior.</p>
</div>
.article-content {
  text-wrap-style: pretty;
}
.article-content h2 {
  text-wrap-style: balance;
}

Important Consideration

Inherited wrapping styles do not guarantee identical line breaks. Different widths, fonts, and font sizes can produce different results in descendant elements.

Practical Examples

Balanced Page Heading

.page-heading {
  max-width: 700px;
  text-wrap-style: balance;
}

Balanced Card Title

.card-title {
  max-width: 28ch;
  text-wrap-style: balance;
}

Pretty Paragraph Wrapping

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

Article Introduction

.article-introduction {
  font-size: 1.2rem;
  line-height: 1.6;
  text-wrap-style: pretty;
}

Balanced Quotation

.featured-quote {
  max-width: 40ch;
  text-wrap-style: balance;
}

Editable Content

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

Normal Wrapping Style

.standard-text {
  text-wrap-style: auto;
}

Responsive Heading

.responsive-heading {
  max-width: 32ch;
  text-wrap-style: balance;
}
@media (max-width: 600px) {
  .responsive-heading {
    max-width: 100%;
  }
}

Progressive Enhancement

.article-text {
  text-wrap-style: auto;
}
@supports (text-wrap-style: pretty) {
  .article-text {
    text-wrap-style: pretty;
  }
}

Avoiding Short Final Lines

.editorial-text {
  text-wrap-style: pretty;
}
@supports (text-wrap-style: avoid-orphans) {
  .editorial-text {
    text-wrap-style: avoid-orphans;
  }
}

Combining Wrapping Mode and Style

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

Using the Shorthand Instead

.content-heading {
  text-wrap: balance;
}

text-wrap-style Example

This example compares normal wrapping, balanced wrapping, and pretty wrapping using identical text inside containers with the same width.

HTML Example

<div class="text-wrap-style-demo">
  <div class="wrap-sample">
    <strong>text-wrap-style: auto;</strong>
    <p class="wrap-auto">Create Better Looking Text Layouts With Modern CSS Wrapping</p>
  </div>
  <div class="wrap-sample">
    <strong>text-wrap-style: balance;</strong>
    <p class="wrap-balance">Create Better Looking Text Layouts With Modern CSS Wrapping</p>
  </div>
  <div class="wrap-sample">
    <strong>text-wrap-style: pretty;</strong>
    <p class="wrap-pretty">Create Better Looking Text Layouts With Modern CSS Wrapping</p>
  </div>
</div>

CSS Example

.text-wrap-style-demo {
  display: grid;
  gap: 12px;
}
.text-wrap-style-demo .wrap-sample {
  max-width: 340px;
  padding: 16px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
}
.text-wrap-style-demo strong {
  display: block;
  margin-bottom: 10px;
  color: #334155;
  font-size: 14px;
}
.text-wrap-style-demo p {
  max-width: 300px;
  margin: 0;
  color: #1f2937;
  font-size: 21px;
  line-height: 1.4;
}
.text-wrap-style-demo .wrap-auto {
  text-wrap-style: auto;
}
.text-wrap-style-demo .wrap-balance {
  text-wrap-style: balance;
}
.text-wrap-style-demo .wrap-pretty {
  text-wrap-style: pretty;
}
Browser Result
text-wrap-style: auto;

Create Better Looking Text Layouts With Modern CSS Wrapping

text-wrap-style: balance;

Create Better Looking Text Layouts With Modern CSS Wrapping

text-wrap-style: pretty;

Create Better Looking Text Layouts With Modern CSS Wrapping

Understanding the Results

The auto sample uses normal line breaking. The balance sample attempts to make the lines more even, while pretty favors improved line-breaking quality.

Browser Differences

Some browsers may display the pretty and auto samples similarly. Differences also depend on the text, font, and available width.

Experiment With Width

.text-wrap-style-demo p {
  max-width: 240px;
}

Reducing the width changes the available line-breaking opportunities and may make the differences between wrapping styles more noticeable.

Try the Shorthand

.text-wrap-style-demo .wrap-balance {
  text-wrap: balance;
}

The shorthand applies balanced wrapping while also setting the wrapping mode to wrap.

Accessibility Considerations

Text wrapping affects readability, responsive layout, and the ability to comfortably read content at different screen sizes and zoom levels.

Allow Text to Reflow

Text should generally remain able to wrap when the available width becomes smaller.

Use Readable Line Lengths

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

Avoid Excessively Narrow Containers

Very narrow text containers can produce awkward wrapping even when advanced wrapping styles are enabled.

Support Text Enlargement

Test layouts with enlarged text and browser zoom to ensure that line wrapping remains readable.

Preserve Semantic Structure

Use appropriate HTML elements for headings, paragraphs, and lists rather than relying on visual line breaks to communicate structure.

Test Different Languages

Line-breaking opportunities vary by language and writing system. Use appropriate language markup and test multilingual content.

Avoid Relying on Exact Line Breaks

Advanced wrapping styles do not guarantee identical line breaks across browsers or devices.

Provide Fallbacks

Content should remain readable when advanced wrapping styles are unsupported.

Maintain Comfortable Line Spacing

Use an appropriate line-height so that wrapped lines remain easy to follow.

Common Mistakes

Using wrap Instead of auto

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

The wrap keyword belongs to text-wrap-mode.

Using nowrap as a Wrapping Style

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

Use text-wrap-mode: nowrap to disable soft wrapping.

Using normal Instead of auto

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

The correct keyword for normal line-breaking behavior is auto.

Combining Multiple Styles

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

Only one wrapping-style keyword is permitted.

Using Length Values

.example {
  text-wrap-style: 300px;
}

Use width or max-width to control the text container width.

Expecting balance to Work on Long Paragraphs

Browsers may limit balancing to relatively short text blocks.

Expecting pretty to Remove Every Orphan

Pretty wrapping is a preference rather than a guarantee of a particular final line length.

Assuming avoid-orphans Is Widely Supported

The value is newer and requires compatibility testing.

Expecting Stable Wrapping to Prevent All Changes

Editing earlier text or resizing a container can still change line breaks.

Ignoring Wrapping Mode

Advanced wrapping styles have no practical soft-line-breaking effect when text-wrap-mode is set to nowrap.

Forgetting Shorthand Reset Behavior

A later text-wrap shorthand declaration can reset the wrapping style.

Expecting Identical Results Across Browsers

Line-breaking algorithms, font metrics, and supported features can differ.

Ignoring Inheritance

Wrapping styles can be inherited by nested elements and may need to be overridden for specific content.

Important Considerations

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

  • The property controls how browsers choose soft line breaks.
  • It is a longhand component of the text-wrap shorthand.
  • The initial value is auto.
  • The property is inherited.
  • The auto value uses normal line-breaking behavior.
  • The balance value attempts to balance line lengths.
  • The pretty value favors improved line-breaking quality.
  • The stable value is intended to reduce unnecessary line changes during editing.
  • The avoid-orphans value targets short final lines and has limited support.
  • Only one wrapping-style keyword can be specified at a time.
  • The property does not determine whether wrapping is permitted.
  • Use text-wrap-mode to enable or disable soft wrapping.
  • Advanced styles have no practical soft-wrapping effect when wrapping is disabled.
  • Balancing is most useful for short text blocks.
  • Pretty wrapping is often useful for paragraphs.
  • Stable wrapping can be useful in editable content.
  • Browsers may limit balancing for performance reasons.
  • Font metrics affect line-breaking results.
  • Container width affects the available line-breaking opportunities.
  • Language-specific line-breaking rules still apply.
  • Advanced wrapping styles may produce different results across browsers.
  • The property does not control font size or line height.
  • Shorthand declarations can reset wrapping-style values.
  • Test text wrapping at different screen widths and zoom levels.
  • Use advanced values as progressive enhancements when compatibility is uncertain.

Browser Support

The CSS text-wrap-style property is available in modern browsers, but support varies by value. The balance and pretty values have been implemented in many modern browser versions, while newer values such as avoid-orphans have more limited support.

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

Basic Declaration

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

Feature Detection

@supports (text-wrap-style: balance) {
  .heading {
    text-wrap-style: balance;
  }
}

Checking pretty Support

@supports (text-wrap-style: pretty) {
  .article-text {
    text-wrap-style: pretty;
  }
}

Checking avoid-orphans Support

@supports (text-wrap-style: avoid-orphans) {
  .article-text {
    text-wrap-style: avoid-orphans;
  }
}

Fallback Behavior

Browsers that do not recognize a value ignore that declaration and retain the previously applicable wrapping style.

Testing Recommendations

Test advanced wrapping styles with the actual fonts, content, and container widths used on the website. Feature queries confirm syntax recognition but do not guarantee identical line-breaking results.

Specifications

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

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

The specification defines the available line-breaking strategies and their relationship to the text-wrap shorthand.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: text-wrap-style