CSS Snippet

Multi-line Text Truncation

Difficulty: Medium

Single-line truncation is solved with `text-overflow: ellipsis`, but truncating to N lines requires the WebKit line-clamp API. This snippet covers the standard three-line ellipsis using the modern `line-clamp` shorthand, the older `-webkit-line-clamp` form for broader support, and a JS-free fade-out variant for browsers without line-clamp.

Code Snippets
/

Multi-line Text Truncation

Multi-line Text Truncation

Single-line truncation is solved with `text-overflow: ellipsis`, but truncating to N lines requires the WebKit line-clamp API. This snippet covers the standard three-line ellipsis using the modern `line-clamp` shorthand, the older `-webkit-line-clamp` form for broader support, and a JS-free fade-out variant for browsers without line-clamp.

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

585 views

13

Five lines of CSS, but every one matters. display: -webkit-box plus -webkit-box-orient: vertical opt the box into the WebKit line-clamp model, -webkit-line-clamp sets the line count, and overflow: hidden clips the rest with an ellipsis. The unprefixed line-clamp is now in the standard track and works without the prefixes on modern browsers, but the prefixed properties are still needed for older Safari and Edge. The container needs a finite width or the truncation never engages.