text-overflow: ellipsis
Single-line ellipsis
The ellipsis needs three declarations working together: the text must be kept to one line (white-space: nowrap), the box must clip it (overflow: hidden), and only then does text-overflow: ellipsis have an overflow to mark. It also needs a box with a width that can be smaller than the text — which in flex and grid is its own entry below.
updated 2 days ago
Use it for
- File names, email subjects, breadcrumb segments, table cells — anywhere a row must stay one line tall.
- Pair it with a title attribute or a tooltip, so the full text is still reachable.
Watch for
- It applies to block containers. On an inline span it does nothing until the span is display: block or inline-block, or is a flex or grid item.
- The middle of a string is often the part that matters — a path’s file name, an ID’s last characters. CSS can only cut the end; middle truncation needs two elements or script.
- Truncated text is hidden from sighted users but still read in full by a screen reader, which is normally what you want. Do not truncate the accessible name yourself.
- A truncated heading that is the only place a piece of information appears is a content problem, not a CSS one.
.truncate { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }