CSS Portal

CSS text-wrap Property

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The text-wrap property controls whether and how inline text content is allowed to break and continue onto subsequent lines within its containing box. At a conceptual level it determines whether long sequences of characters (words, URLs, or other continuous runs) may wrap to the next line or must remain unbroken, and it therefore directly affects line breaking opportunities, container height, and horizontal overflow. When used carefully, it is one of the primary tools for managing how textual content adapts to narrow viewports, responsive columns, and tight UI regions.

Because line breaking is the result of multiple interacting rules, text-wrap is most useful when considered alongside related layout properties. For example, it complements white-space, which governs whether normal whitespace can create wrap opportunities at all and whether sequences of spaces are collapsed; it works together with overflow-wrap (formerly word-wrap) that provides additional opportunities to break long words to avoid overflow; and it interacts with word-break, which can change line-break behavior for certain languages and scripts. Automatic hyphenation provided by hyphens can further refine where a wrapped word is split, improving visual flow and readability.

In practical layout work, text-wrap helps prevent unwanted horizontal scroll and clipped text in cards, buttons, table cells, and navigation items by allowing content to reflow instead of forcing the box to grow. Conversely, when you need tightly controlled single-line elements (such as badges or tagged labels) you may intentionally disable wrapping and combine that with truncation techniques; in fluid layouts, enabling controlled wrapping can reduce the need for JavaScript resizing hacks. Because wrapping affects line count, it also influences vertical rhythm and the calculation of heights in flex and grid items — enabling wrap can change alignment and spacing unexpectedly, so always verify behavior across breakpoints.

From a readability and internationalization perspective, wrapping behavior should respect language and typographic conventions: different scripts and punctuation habits produce different desirable break points, and allowing intelligent breaks (often via the other properties above) improves comprehension. Also consider the visual balance of lines — too-aggressive wrapping can create rivers or ragged edges that hurt legibility, while too-lenient settings can force awkward overflows. In short, use text-wrap as part of a small set of complementary properties to produce robust, readable, and responsive text layouts.

Definition

Initial value
wrap
Applies to
text and block containers
Inherited
yes
Computed value
as specified
Animatable
yes
JavaScript syntax
object.style.textWrap

Syntax

text-wrap: wrap | nowrap | balance | pretty | stable

Values

  • wrapText wraps at normal break points (e.g., spaces) to stay within the container.
  • nowrapext does not wrap - long lines overflow the container instead of breaking.
  • balance Text wraps so that line lengths are evenly balanced, improving legibility for short blocks like headings. Browsers currently limit this to a small number of lines for performance.
  • pretty Similar to wrap but uses a slower algorithm to optimize typographic quality, reducing orphans and improving overall text flow.
  • stableBehaves like wrap, but when editing content (e.g., in a contenteditable element), earlier lines stay stable instead of reflowing as text changes.

Example

<div class="container">
<h2>Text-wrap: balance - comparison</h2>

<div class="example">
<div class="label">With text-wrap: balance</div>
<p class="balanced">This is a long sentence that demonstrates how the CSS text-wrap property balances line breaks across multiple lines to produce more even, readable line lengths in a constrained container.</p>
</div>

<div class="example">
<div class="label">Normal wrapping (default)</div>
<p class="normal">This is a long sentence that demonstrates how the CSS text-wrap property balances line breaks across multiple lines to produce more even, readable line lengths in a constrained container.</p>
</div>
</div>
/* Container and general styles */
.container {
  max-width: 520px;
  margin: 28px auto;
  padding: 18px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: #f5f7fb;
  border-radius: 10px;
  color: #0f172a;
}

h2 {
  margin: 0 0 14px;
  font-size: 1.15rem;
  color: #0b1220;
}

.example {
  margin-bottom: 12px;
}

.label {
  font-size: 0.85rem;
  color: #334155;
  margin-bottom: 6px;
}

p {
  margin: 0;
  padding: 12px;
  background: #ffffff;
  border-radius: 8px;
  line-height: 1.35;
  font-size: 1rem;
  box-shadow: 0 1px 0 rgba(2,6,23,0.04) inset;
}

/* Demonstrate the text-wrap property */
.balanced {
  /* Preferred modern property value  -  asks the UA to balance line breaks */
  text-wrap: balance;
  /* WebKit prefix for some implementations */
  -webkit-text-wrap: balance;
}

/* The normal paragraph shows default wrapping for comparison */
.normal {
  /* no special text-wrap; behaves as the browser default */
}

Browser Support

The following information will show you the current browser support for the CSS text-wrap property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 1st January 2026

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!