`line-clamp` Is Standardized Now. No Browser Ships It By Default.
Open any card grid — a blog's post list, a product catalog, a comment thread — and find the one where the description is cut off after three lines with a neat little …. Then view source on the CSS. It's always the same f
Open any card grid — a blog's post list, a product catalog, a comment thread — and find the one where the description is cut off after three lines with a neat little …. Then view source on the CSS. It's always the same four lines, and I'd bet money whoever wrote them couldn't tell you why all four are required.
.card-desc {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
overflow: hidden;
}
-webkit-line-clamp is a non-standard, vendor-prefixed property that's been in Blink and WebKit since around 2010. It's not part of any spec. It only works if you also opt the element into display: -webkit-box — a legacy, pre-flexbox box layout model that competed with flexbox and lost, fifteen years ago. You can't use it on a flex or grid item without fighting your own layout, because display: -webkit-box is the display value now, overwriting whatever you actually wanted there.
And yet it's the only reliable way to truncate text after N lines. text-overflow: ellipsis — the normal, standard property everyone assumes handles this — only works on a single line of white-space: nowrap text. The moment your card description wraps to two or three lines, text-overflow has nothing to say about it. There is no standard multi-line equivalent. There never has been.
Before you keep reading: have you ever wondered why nobody writes a non-prefixed version of this? It's not that browser vendors forgot. It's that until recently, there wasn't one to write.
The CSS Overflow spec finally caught up
Multi-line truncation is specified now, as a real property: line-clamp. No vendor prefix, no -webkit-box detour — you set it on a normal block-level element and the browser clips it after the given number of lines, ellipsis included.
.card-desc {
line-clamp: 3;
}
That's the whole point of standardizing it: you keep whatever display you actually need — block, flex, grid, doesn't matter — instead of being forced into a legacy layout mode just to get an ellipsis.
Here's the part that surprised me enough to write this post: no browser ships the unprefixed line-clamp to regular users yet — not in any stable release, anywhere. Safari's implementation is the most complete of the three, but it's only ever lived in Safari Technology Preview — Apple's experimental, developer-only pre-release channel, not the Safari your actual users run — and WebKit's own tracking bug for it ("Finish implementing and enable non-prefixed line-clamp") is still open. (Safari briefly exposed it by accident in the 18.2–18.3 stable releases, then removed it again in 18.4.) Chrome has had a version prototyped behind its experimental-web-platform-features flag since early 2024, with spec and implementation work still ongoing and no public Intent to Ship yet. Firefox gates it behind its own layout.css.line-clamp.enabled pref, off by default even in Nightly. Three browsers, three different half-finished attempts, and not one has reached a browser a real visitor is running by default.
Guess which browser has gotten the standardized version furthest along, before I told you. If you guessed Safari, you're right — just not the way you'd think. "Furthest along" here means "most polished inside an experimental preview channel," not "shipped to anyone."
So what do you actually ship today
Not line-clamp alone — not yet. If you only write the unprefixed property, every browser that doesn't understand it yet ignores the declaration entirely, your card descriptions render in full, and your card grid layout breaks the moment one product has a three-paragraph description instead of two sentences. The old four-line hack is still the one that works everywhere, so it stays as the baseline, with the new property layered on top for browsers that understand it:
.card-desc {
overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
}
@supports (line-clamp: 3) {
.card-desc {
display: block;
line-clamp: 3;
}
}
The @supports block only applies in browsers that actually understand line-clamp, and it explicitly resets display back to block there — so you get the modern property doing the clamping, on a normal block element, with none of the legacy box-model baggage, in exactly the browsers that support it. Everywhere else, the first block keeps doing the job it's always done. Nobody has to maintain two copies of the layout.
🎮 Try it yourself
▶️ Open the interactive playground →
Runs right in your browser — poke at it and watch the concept react live.
The thing the hack never told you
The clamp is purely visual. overflow: hidden clips the rendered box — it doesn't delete the trailing sentences from the DOM. Select the card's text and drag past the ellipsis; the hidden words are still there, still selectable, because nothing was ever removed, only the rendering of the overflow was clipped. If your "show more" button just toggles a class that flips -webkit-line-clamp to unset or line-clamp to none, you're not re-fetching or re-rendering anything — the full text was sitting there the entire time.
That's also why this never substitutes for actually trimming a string server-side if you care about what a screen reader announces, or what gets indexed — the full text is present in the accessibility tree and the page source either way. Truncating for layout and truncating for content are two different problems, and this property only solves the first one.
What to actually do with this on Monday
If your team's truncation mixin still only has the four -webkit- lines, you're not behind — that's still correct, because it's still the only version every shipping browser understands, Safari included: its unprefixed implementation hasn't left Safari Technology Preview. Wrapping it in the @supports block above costs you nothing and means the day any browser actually ships line-clamp for good, your cards are already using the real property instead of the workaround, with no further changes needed.
Next time you paste that four-line incantation into a new component, you'll at least know what it's secretly turning your display into, and why the standard finally gave it a name. Which other "obviously vendor-only" CSS hack from a decade ago do you think is quietly becoming a real property next?
🧠 Test yourself
Think it clicked? Take the 7-question quiz →
Instant feedback, a hint on every question, and an explanation for each answer — right or wrong.
📚 Read next
- Stop Fixing Headline Gaps With Negative Margins. Use
text-box-trim - Stop Writing Media Queries for Font Size
- You hand-edit headlines to avoid orphaned words.
text-wrap: balancedoes it natively.
🚀 Want more like this? Every guide, playground, and quiz lives on bestpractic.org — open it and sign up free so the next one finds you.
Thanks for reading! Let's stay connected:
- ⭐ GitHub — follow me and star the projects: github.com/parsajiravand
- 💬 Discord — join the frontend best-practices community: discord.gg/d9KRhuAwQ
- 📸 Instagram — frontend best practices, daily: @bestpractice___
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.