Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Typography

The text-overflow property

Reference for the CSS text-overflow property: truncate overflowing lines with an ellipsis or clip, the three required companion declarations, flex and table pitfalls.

The text-overflow property decides what happens at the end of a line of text that does not fit its box. With clip (the default) the text is simply cut off. With ellipsis the browser replaces the cut part with an ellipsis character so readers can tell something is missing.

The property only changes how the overflow is shown. It does not create the overflow, and it does not hide anything by itself. For the classic single-line truncation you always need three declarations working together.

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

Try it

Clip versus ellipsis

The third box shows the most common mistake: text-overflow: ellipsis has no effect while overflow is visible.

Syntax

CSS
text-overflow: [ clip | ellipsis | <string> ]{1,2}
  • Initial value: clip
  • Applies to: block containers
  • Inherited: no
  • Animatable: no
  • Computed value: as specified

Values

Value Description
clip Cuts the text at the edge of the box. A glyph can be sliced in half.
ellipsis Replaces the hidden end of the line with an ellipsis character (โ€ฆ).
<string> A custom string shown instead of the hidden text. Browser support is limited, so check a compatibility table before using it.
two values The first applies to the left end of the line, the second to the right end (the line-end and line-start in other writing directions).

Usage notes

  • Three ingredients. Truncation needs overflow set to something other than visible, white-space: nowrap (otherwise the text wraps and does not overflow horizontally), and a constrained width.
  • Only whole inline overflow. text-overflow works on a single line. To cut text after several lines, use the line-clamp technique described in Wrapping, Overflow and Hyphens instead.
  • Flex and grid items. A flex item has min-width: auto, so it refuses to shrink below its text. Add min-width: 0 (or overflow: hidden) to the item so the ellipsis can appear.
  • Table cells. Cells size to their content. Use table-layout: fixed or give the cell a max-width before truncation works.
  • Accessibility. The full text is still in the DOM, so screen readers read all of it. Sighted users lose the hidden part, so offer a title, a tooltip, or a way to expand when the text matters.
  • Scrolling boxes. With overflow: auto or scroll, the ellipsis shows while text is clipped and disappears as the user scrolls it into view.

Browser support

clip and ellipsis work in every current browser; custom <string> values and the two-value form are less consistent, so test them.