CSS Snippet

Truncate Text with Ellipsis

Difficulty: Easy

Single-line text truncation is one of the most common UI requirements: titles, table cells, breadcrumbs. Done wrong, the text wraps or overflows. Done right, it shrinks with a clean ellipsis. This snippet covers the three-line single-line recipe, an inline variant that needs `min-width: 0` inside flex parents, and a tooltip-friendly version that exposes the full text on hover.

Code Snippets
/

Truncate Text with Ellipsis

Truncate Text with Ellipsis

Single-line text truncation is one of the most common UI requirements: titles, table cells, breadcrumbs. Done wrong, the text wraps or overflows. Done right, it shrinks with a clean ellipsis. This snippet covers the three-line single-line recipe, an inline variant that needs `min-width: 0` inside flex parents, and a tooltip-friendly version that exposes the full text on hover.

CSS
Easy
3 snippets
css-selectors
css-overflow
code-template
cheat-sheet

808 views

20

These three properties always travel together. white-space: nowrap prevents wrapping, overflow: hidden clips anything past the box edge, and text-overflow: ellipsis swaps the clip for a .... Without all three, the text either wraps or overflows visibly. The container also needs an explicit width or max-width; otherwise it expands to fit the content and the ellipsis never appears. This is the version to drop into a utility class and reach for everywhere.