Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Typography

The -webkit-line-clamp property

Reference for -webkit-line-clamp: truncate text after a number of lines with an ellipsis, the required companion properties, a live example and pitfalls.

The -webkit-line-clamp property cuts a block of text after a given number of lines and ends the last visible line with an ellipsis. It is the standard way to build card descriptions, article teasers and list previews that all take the same height.

Despite the prefix, it works in all current browsers. It only does its job together with two other legacy declarations: display: -webkit-box and -webkit-box-orient: vertical, plus overflow: hidden. An unprefixed line-clamp property is being specified, but it is not widely usable yet, so keep using the prefixed form for now.

CSS
.teaser {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}

Try it

A clamped card with a toggle

The paragraph shows three lines and an ellipsis. The button sets -webkit-line-clamp: none through a class, which shows the full text.

Syntax

CSS
-webkit-line-clamp: none | <integer>;
Initial value none
Applies to block containers displayed as -webkit-box (the legacy flexbox)
Inherited no
Animatable not in practice
Computed value as specified

Values

Value Description
none No clamping: all lines are shown.
<integer> The maximum number of lines to show, 1 or more. An ellipsis replaces the end of the last line when text is cut.

Usage notes

  • All four declarations are needed. display: -webkit-box, -webkit-box-orient: vertical, -webkit-line-clamp and overflow: hidden. If you forget one, nothing is clamped.
  • Do not put padding on the clamped element. Extra lines of text can show through in the padding area below the last clamped line. Put padding on a wrapper element and clamp an inner element.
  • No display: flex on the same element. The clamp depends on -webkit-box. If you switch the same element to flex or grid, the clamp stops working.
  • Not just a visual change. The hidden text is still in the page, so screen readers and search engines can access it. Provide a way to read the full text, like the "Show more" button above, when the text is important.
  • Clamping by height instead. If your text is shorter than the limit, nothing changes. If you need a fixed height and not a fixed number of lines, use max-height with overflow: hidden, but the cut can land in the middle of a line.
  • One-line truncation. For a single line, text-overflow: ellipsis with white-space: nowrap is a simpler tool.
  • Unprefixed version. The standard line-clamp is being specified in CSS Overflow, with extra features for the ellipsis and for continuing text in another region. Check a compatibility table before using it without a prefix.

Browser support

The prefixed form works in all current browsers, including Chrome, Safari, Firefox and Edge. The unprefixed line-clamp property is new and should be checked in a compatibility table.