CSS text-overflow Property

The CSS text-overflow property controls how clipped inline text is represented when it extends beyond the visible edge of its container.

It can simply clip overflowing text, display an ellipsis (...), or use a custom string in supporting browsers. The property is commonly used for navigation labels, table cells, filenames, and other text that must fit within a limited space.

The text-overflow property does not cause text to overflow or hide it by itself. It works with other CSS properties that constrain the available space and clip overflowing content.

text-overflow Syntax

The text-overflow property accepts keywords or strings that determine how clipped text is indicated at the inline edges of a line.

Basic Syntax

.example {
  text-overflow: ellipsis;
}

Available Values

.example {
  text-overflow: clip;
}
.example {
  text-overflow: ellipsis;
}
.example {
  text-overflow: "...";
}

Custom strings are defined in the CSS Overflow specification but are not supported consistently across browsers.

Two-Value Syntax

.example {
  text-overflow: clip ellipsis;
}
.example {
  text-overflow: ellipsis ellipsis;
}

With two values, the first controls the inline-start side and the second controls the inline-end side. Support for two-value syntax varies.

CSS-Wide Keywords

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

The initial value is clip. The property is not inherited, so unset restores the initial value.

Valid Examples

.label {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.label {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: clip;
}
.label {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis ellipsis;
}

Invalid Examples

.example {
  text-overflow: hidden;
}
.example {
  text-overflow: fade;
}
.example {
  text-overflow: 20px;
}
.example {
  text-overflow: clip ellipsis clip;
}

The property does not accept hidden, numeric lengths, or three overflow markers. The fade keyword is not part of the widely implemented CSS Overflow Level 3 syntax.

Property Values

Value Description
clip Clips overflowing inline text at the content area's edge without displaying an additional marker.
ellipsis Displays an ellipsis character to indicate that text has been clipped.
<string> Displays a specified string as the overflow marker. Browser support is limited.
Two values Specifies separate overflow behavior for the inline-start and inline-end sides. Browser support varies.

Property Characteristics

Characteristic Value
Initial value clip
Inherited No
Applies to Block containers
Computed value Specified value
Animation type Discrete
Percentages Not applicable
Lengths Not accepted in the Level 3 syntax
Specification CSS Overflow Module Level 3

Note: The text-overflow property affects the visual representation of clipped inline content. It does not remove the underlying text from the document.

How It Works

Text overflow occurs when inline content requires more space than the container provides. The browser uses the text-overflow value to determine whether a marker should appear at the clipped edge.

Step 1: Create a Constrained Container

.overflow-label {
  width: 220px;
}

Step 2: Prevent Line Wrapping

.overflow-label {
  width: 220px;
  white-space: nowrap;
}

The text remains on one line, even if it exceeds the available width.

Step 3: Clip Overflowing Content

.overflow-label {
  width: 220px;
  white-space: nowrap;
  overflow: hidden;
}

Content beyond the container's visible area is clipped.

Step 4: Display an Ellipsis

.overflow-label {
  width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

When the text exceeds the available width, the browser displays an ellipsis near the clipped edge.

Important Consideration

The browser must have enough room to display the ellipsis. In extremely narrow containers, the marker itself may be clipped.

The clip Value

The clip value hides overflowing text without adding an ellipsis or another indicator.

Basic Example

.clipped-text {
  width: 200px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: clip;
}

HTML Example

<p class="clipped-text">
  This is a long line of text that extends beyond the container.
</p>

How clip Behaves

Text that extends beyond the visible edge is cut off. Depending on where the edge falls, clipping can occur within a character.

Default Behavior

Because clip is the initial value, it does not need to be explicitly declared when no overflow marker is required.

When to Use clip

Use clip when the layout intentionally hides overflowing text and does not need a visual indicator.

Important Consideration

Users may not realize that additional text exists. Avoid clipping important information without providing another way to access it.

The ellipsis Value

The ellipsis value displays an ellipsis character to indicate that part of the text is hidden.

Basic Example

.ellipsis-text {
  width: 200px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

HTML Example

<p class="ellipsis-text">
  This is a long line of text that extends beyond the container.
</p>

How the Ellipsis Appears

The browser reserves space for the ellipsis and clips enough text to accommodate it. The exact number of visible characters depends on the font and container width.

Using max-width

.ellipsis-text {
  max-width: 250px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

This allows the element to remain flexible while limiting its maximum width.

Using Inline-Block Elements

.inline-label {
  display: inline-block;
  max-width: 180px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  vertical-align: bottom;
}

Inline-block elements can use constrained widths and display ellipses within surrounding inline content.

Important Consideration

The ellipsis is a visual marker, not a replacement for the hidden text. The full text remains in the document and should be accessible when needed.

Custom Overflow Strings

The CSS Overflow specification allows a custom string to be used as an overflow marker.

Custom String Example

.custom-overflow {
  width: 200px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: "[more]";
}

Using an Empty String

.custom-overflow {
  text-overflow: "";
}

An empty string can request clipping at character boundaries in browsers that support string values.

Fallback Example

.custom-overflow {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
@supports (text-overflow: "[more]") {
  .custom-overflow {
    text-overflow: "[more]";
  }
}

Browsers that do not recognize custom strings retain the ellipsis declaration.

Browser Compatibility

Custom overflow strings have limited browser support and should not be relied upon without testing.

Important Consideration

A custom overflow marker is not an interactive control. If users need to reveal hidden content, provide an actual button, link, or expandable interface.

Two-Value Syntax

The two-value syntax allows different overflow markers at the inline-start and inline-end edges of a line.

Basic Example

.two-sided-overflow {
  text-overflow: clip ellipsis;
}

The first value applies to the inline-start edge and the second applies to the inline-end edge.

Ellipses at Both Edges

.two-sided-overflow {
  text-overflow: ellipsis ellipsis;
}

Different Edge Markers

.two-sided-overflow {
  text-overflow: ellipsis clip;
}

When Both Edges Overflow

Two-sided markers are most useful when inline content can be clipped at both ends, such as within a horizontally scrolled container.

Single-Value Behavior

.single-value {
  text-overflow: ellipsis;
}

A single value applies to the inline-end edge. The inline-start edge uses clipping without an additional marker.

Browser Compatibility

Two-value syntax is not supported consistently across all browsers. Use a single ellipsis value as a fallback when necessary.

Fallback Example

.two-sided-overflow {
  text-overflow: ellipsis;
}
@supports (text-overflow: ellipsis ellipsis) {
  .two-sided-overflow {
    text-overflow: ellipsis ellipsis;
  }
}

Required CSS Properties

The text-overflow property works only when the text is clipped in the inline direction. For a typical single-line ellipsis, three declarations are commonly used together.

Complete Single-Line Pattern

.truncated-text {
  width: 240px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

The overflow Property

.truncated-text {
  overflow: hidden;
}

This prevents content beyond the visible boundary from being displayed.

The white-space Property

.truncated-text {
  white-space: nowrap;
}

This prevents normal line wrapping, allowing long text to overflow horizontally in a typical horizontal writing mode.

A Width Constraint

.truncated-text {
  max-width: 240px;
}

A width constraint gives the browser a boundary at which overflow can occur.

Flexbox Considerations

.flex-item {
  min-width: 0;
}
.flex-item .truncated-text {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

Flex items may resist shrinking because of their automatic minimum size. Setting min-width: 0 on the appropriate flex item can allow text truncation to work.

Grid Considerations

.grid-container {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
}
.grid-label {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

The minmax(0, 1fr) track allows the text column to shrink below its content's intrinsic width.

Important Consideration

If the element expands to fit its content, no clipping occurs and the ellipsis will not appear.

Text Direction

Overflow markers follow the inline direction of the text rather than always appearing on the physical right side.

Left-to-Right Text

.ltr-text {
  direction: ltr;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

For typical left-to-right text, the ellipsis appears at the right edge when the text overflows.

Right-to-Left Text

.rtl-text {
  direction: rtl;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

For right-to-left text, the inline-end edge is on the left, so the ellipsis normally appears there.

HTML Direction Attribute

<p dir="rtl" class="rtl-text">
  هذا مثال على نص طويل يتم اقتطاعه عند تجاوز المساحة المتاحة.
</p>

Vertical Writing Modes

.vertical-text {
  writing-mode: vertical-rl;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

In vertical writing, the inline direction runs vertically. The overflow marker follows the corresponding inline edge.

Important Consideration

Use the correct language and direction information for the content rather than forcing a direction solely to move the ellipsis.

Multiline Text

The text-overflow property is designed to indicate clipped inline content at line edges. It does not provide a standard way to limit a paragraph to a specified number of lines.

Single-Line Ellipsis

.single-line {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

Multiline Clamping

.multiline-clamp {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}

This commonly supported legacy technique limits visible content to three lines and displays a truncation indicator where supported.

Using line-clamp

.multiline-clamp {
  line-clamp: 3;
}

The unprefixed line-clamp property is being standardized, but support varies. The declaration alone should not be relied upon for consistent multiline truncation.

Fallback for Multiline Content

When multiline clamping is unavailable, allow the paragraph to display normally or use an interface that lets users expand and collapse the content.

Important Consideration

Do not assume text-overflow: ellipsis will automatically create an ellipsis at the bottom of a fixed-height, multiline paragraph.

Practical Examples

Truncated Filename

.filename {
  display: block;
  max-width: 260px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

Navigation Label

.navigation-label {
  display: inline-block;
  max-width: 150px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

Table Cell

.data-table {
  table-layout: fixed;
  width: 100%;
}
.data-table td {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

Card Heading

.card-title {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

Flexbox Label

.toolbar-item {
  display: flex;
  min-width: 0;
}
.toolbar-label {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

Grid Label

.grid-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
}
.grid-label {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

Right-to-Left Text

.rtl-label {
  direction: rtl;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

Custom Marker With Fallback

.custom-label {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
@supports (text-overflow: "[more]") {
  .custom-label {
    text-overflow: "[more]";
  }
}

Reveal Full Text on Focus

.focus-label {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.focus-label:focus {
  white-space: normal;
  overflow: visible;
}

For this technique, make the element keyboard-focusable when appropriate and ensure the expanded content does not overlap surrounding controls.

text-overflow Example

This example compares the clip and ellipsis values using identical text and container widths. A third sample demonstrates how an ellipsis responds to a narrower container.

HTML Example

<div class="text-overflow-demo">
  <div class="overflow-sample">
    <strong>clip</strong>
    <p class="overflow-clip">A complete guide to modern CSS layout techniques</p>
  </div>
  <div class="overflow-sample">
    <strong>ellipsis</strong>
    <p class="overflow-ellipsis">A complete guide to modern CSS layout techniques</p>
  </div>
  <div class="overflow-sample">
    <strong>ellipsis with a narrow width</strong>
    <p class="overflow-narrow">A complete guide to modern CSS layout techniques</p>
  </div>
</div>

CSS Example

.text-overflow-demo {
  display: grid;
  gap: 16px;
}
.text-overflow-demo .overflow-sample {
  padding: 16px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
}
.text-overflow-demo strong {
  display: block;
  margin-bottom: 10px;
  color: #334155;
  font-size: 14px;
}
.text-overflow-demo p {
  margin: 0;
  width: 260px;
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  color: #1f2937;
  font-size: 16px;
  line-height: 1.6;
}
.text-overflow-demo .overflow-clip {
  text-overflow: clip;
}
.text-overflow-demo .overflow-ellipsis {
  text-overflow: ellipsis;
}
.text-overflow-demo .overflow-narrow {
  width: 150px;
  text-overflow: ellipsis;
}
Browser Result
clip

A complete guide to modern CSS layout techniques

ellipsis

A complete guide to modern CSS layout techniques

ellipsis with a narrow width

A complete guide to modern CSS layout techniques

Comparing the Results

Sample Expected Appearance
clip Overflowing text is cut off without a marker.
ellipsis An ellipsis indicates that the text continues beyond the visible area.
Narrow ellipsis Fewer characters remain visible because the available width is smaller.

Changing the Width

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

Reducing the width causes the text to be clipped earlier.

Allowing Text to Wrap

.text-overflow-demo p {
  white-space: normal;
}

The text can wrap onto additional lines, so the single-line ellipsis behavior is no longer demonstrated.

Removing Overflow Clipping

.text-overflow-demo p {
  overflow: visible;
}

The text can extend beyond its container instead of being clipped, preventing the usual ellipsis behavior.

Accessibility Considerations

Truncating text can make interfaces more compact, but it may also hide information that users need.

Preserve the Full Text

Keep the complete text in the HTML rather than replacing it with a shortened string whenever possible.

Provide Access to Hidden Information

If the full text is important, provide a way to reveal it through an expandable section, accessible tooltip, or another appropriate interface.

Do Not Rely Only on Hover

Hover-only solutions may be inaccessible to keyboard and touch users.

Use Meaningful Labels

Ensure that truncated navigation links and buttons retain accessible names that describe their purpose.

Avoid Truncating Critical Information

Important instructions, error messages, and form labels should remain available without requiring users to guess hidden content.

Test Text Resizing

Enlarged text may cause truncation to occur earlier. Verify that essential information remains accessible at increased zoom levels.

Consider Responsive Layouts

Allow text to wrap on smaller screens when truncation would make content difficult to understand.

Maintain Keyboard Access

Any control used to reveal hidden text should be accessible by keyboard.

Avoid Misleading Ellipses

An ellipsis indicates hidden text, but it does not automatically mean the text can be expanded. Provide a clear interaction when expansion is available.

Common Mistakes

Using text-overflow Alone

.example {
  text-overflow: ellipsis;
}

This does not establish the clipping and width constraints needed for a typical ellipsis.

Correct Single-Line Pattern

.example {
  width: 220px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

Forgetting overflow: hidden

When overflowing content remains visible, the browser does not display the usual clipped-text marker.

Forgetting white-space: nowrap

Text may wrap instead of overflowing along a single line.

Not Constraining the Width

If the element grows to fit the entire text, no overflow occurs.

Using hidden as a Value

.example {
  text-overflow: hidden;
}

Use overflow: hidden to clip content and text-overflow to control the marker.

Expecting Multiline Ellipses

The property does not automatically limit paragraphs to a specified number of lines.

Using Unsupported Custom Strings

Custom overflow strings are not consistently supported across browsers.

Ignoring Flexbox Minimum Sizes

A flex item may need min-width: 0 before its content can shrink and display an ellipsis.

Ignoring Grid Track Minimum Sizes

Grid tracks may need minmax(0, 1fr) or another suitable constraint.

Expecting the Ellipsis to Be Interactive

The ellipsis is a visual indicator, not a button or link.

Hiding Important Content

Users should have a reliable way to access information that is essential to understanding or completing a task.

Important Considerations

Keep the following points in mind when using text-overflow:

  • The property controls the representation of clipped inline text.
  • It does not create overflow or clip content by itself.
  • The initial value is clip.
  • The property is not inherited.
  • The clip value hides overflowing text without a marker.
  • The ellipsis value displays an ellipsis when text is clipped.
  • Custom string values have limited browser support.
  • Two-value syntax controls inline-start and inline-end markers separately.
  • Two-value syntax is not supported consistently in all browsers.
  • A single value applies to the inline-end edge.
  • The marker follows the inline direction of the text.
  • Right-to-left text may display the ellipsis on the left.
  • Vertical writing modes use vertical inline edges.
  • A width constraint is commonly needed for single-line truncation.
  • overflow: hidden clips content beyond the visible area.
  • white-space: nowrap prevents normal line wrapping.
  • Flex items may require min-width: 0.
  • Grid tracks may require appropriate minimum-size constraints.
  • The browser reserves space for an ellipsis when necessary.
  • The ellipsis itself may be clipped in extremely narrow containers.
  • The property does not provide standard multiline line clamping.
  • The underlying text remains in the document.
  • Visual truncation should not hide essential information permanently.
  • The ellipsis is not an interactive control.
  • Test truncation with different fonts, widths, languages, and zoom levels.

Browser Support

The CSS text-overflow property is widely available in modern browsers. The clip and ellipsis values are broadly supported in current versions of Chrome, Edge, Firefox, and Safari.

Custom string markers and two-value syntax have more limited or inconsistent support.

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

Widely Supported Example

.truncated-text {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

Custom String Fallback

.truncated-text {
  text-overflow: ellipsis;
}
@supports (text-overflow: "[more]") {
  .truncated-text {
    text-overflow: "[more]";
  }
}

Two-Value Fallback

.truncated-text {
  text-overflow: ellipsis;
}
@supports (text-overflow: ellipsis ellipsis) {
  .truncated-text {
    text-overflow: ellipsis ellipsis;
  }
}

Testing Recommendations

Test truncation in Chrome, Edge, Firefox, and Safari, particularly when using custom strings, two-sided markers, right-to-left text, or vertical writing modes.

Specifications

The text-overflow property is defined in the CSS Overflow Module Level 3 specification.

CSS Overflow Module Level 3 - text-overflow Property

The specification defines how clipped inline text is represented using keywords, strings, and overflow markers at the inline edges.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: text-overflow