Typography Beginner

Multiline text truncation without JavaScript

The old way was JS that counted characters or words and appended "...", or the -webkit-line-clamp plus -webkit-box-orient combo. line-clamp is now in the spec and gives you clean multiline truncation.

7 lines
1.card-title {
2  display: -webkit-box;
3  -webkit-line-clamp: 3;
4  line-clamp: 3;
5  overflow: hidden;
6}
7
8/* Standard; -webkit- prefix still needed. */
Old 10+ lines
1/* JS: slice text, append '...'. */
2/* or measure via getComputedStyle. Breaks on resize. */
3
4.card-title {
5  overflow: hidden;
6  text-overflow: ellipsis;
7}
8
9/* Older: -webkit-line-clamp + -webkit-box-orient */
Widely available Since 2021 96% global usage

This feature is well established and works across many devices and browser versions. It has been available across browsers since 2021.

14+
68+
5+
17+
text is clamped to 3 lines
Clamped (3 lines)

CSS has evolved dramatically over the past few years. Features that once required JavaScript libraries or preprocessor hacks are now available natively in the browser. This text demonstrates line clamping, which truncates content after a specific number of lines and adds an ellipsis. No JavaScript character counting needed.

-webkit-line-clamp: 3
Kinsta

Your first month is free

Managed WordPress hosting for faster sites.

Learn more
⚑

No character math

You choose the line count. The browser adds the ellipsis. No JS, no slicing, no resize listeners.

✦

Spec-backed

line-clamp is in the CSS spec. You keep -webkit-line-clamp for support; same value, future-proof.

∞

Layout-based

Truncation is by lines, not characters. Works with any font size and container width.

Lines Saved
10+ β†’ 7
No JS truncation
Old Approach
JS or -webkit-box-orient
Char count or legacy hack
Modern Approach
line-clamp
Standard property, -webkit- for support

How it works

The old way was either JavaScript that cut the string at a character or word limit and appended "..." (and often broke on resize or different font sizes), or the CSS hack: display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical. The latter worked but relied on a non-standard property and had to be remembered as a set.

The modern way: the spec has line-clamp. You still use display: -webkit-box and -webkit-line-clamp: 3 for broad support, and add line-clamp: 3 so you're using the standard name. overflow: hidden does the rest. No JavaScript, truncation by line count, ellipsis by the browser.

New CSS drops.

Join 600+ readers who've survived clearfix hacks.

ESC