CSS line-clamp property
- Category
- CSS
- Type
- New or changed feature
- Status
- In developer trial (Behind a flag) (Chrome In developer trial (Behind a flag))
- Intent stage
- None
WPT details: https://wpt.fyi/results/css/css-overflow/line-clamp
Summary
Allows clamping a block element to have at most a specific number of text lines, or to have as many lines as will fit in a certain height, showing an ellipsis at the end of the last line. This allows showing a small preview of a longer text, purely in CSS, in a simpler way than was previously possible.
Motivation
The functionality to clamp a block element to a number of lines and show an ellipsis at the end was previously already available through the -webkit-line-clamp property. This property, however, has a number of shortcomings. For instance, it relies on two other deprecated properties for it to work (display: -webkit-box and -webkit-box-orient: vertical), it requires overflow: hidden to be present so the clamped lines would be hidden, and it also only allows clamping based on a number of lines, not a height. The existing -webkit-line-clamp property seems to be a pain point for web developers, and a Chrome use counter shows that its uses without the other properties that are needed for it to work are at 3-4%, showing significant misuse in the wild. Given this, it makes sense to implement a version without these fallbacks.
Standards & signals
- Specification: https://drafts.csswg.org/css-overflow-4/#suppressing-excess
- Firefox: Positive
- Safari: Support
- Web developers: No signals
- Tracking bug: https://issues.chromium.org/issues/40336192
Ecosystem
- Web Platform Tests: https://wpt.fyi/results/?q=css%2Fcss-overflow%2Fline-clamp
- Chrome Platform Showcase: https://chrome-platform-showcase.paulkinlan-ea.deno.net/features
- GenDN reference: https://gendn.paulkinlan-ea.deno.net/features
- chrome.dev demos search: https://www.google.com/search?q=site%3Achrome.dev+CSS%20line-clamp%20property
- MDN Web Docs: https://developer.mozilla.org/en-US/search?q=CSS%20line-clamp%20property
- Baseline status: https://webstatus.dev/?q=CSS%20line-clamp%20property
Docs: https://github.com/Igalia/explainers/blob/main/css/line-clamp/README.md
Explainers: https://github.com/Igalia/explainers/blob/main/css/line-clamp/README.md