-webkit-line-clamp

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

The -webkit-line-clamp CSS property allows limiting of the contents of a block to the specified number of lines.

It only works in combination with the display property set to -webkit-box or -webkit-inline-box and the -webkit-box-orient property set to vertical. Despite them being deprecated, the co-dependency of these three properties is fully specified behavior and will continue to be supported.

In most cases you will also want to set overflow to hidden, otherwise the contents won't be clipped but an ellipsis will still be shown after the specified number of lines.

When applied to anchor elements, the truncating can happen in the middle of the text, not necessarily at the end.

Note: This property was originally implemented in WebKit and has some issues, such as the dependency on two other legacy properties. It got standardized in CSS Overflow Module Level 4 for legacy support. CSS Overflow Module Level 4 also defines a line-clamp property, which is meant to replace this property and avoid its issues. However, all browsers that support line-clamp will also support -webkit-line-clamp for compatibility reasons.

Syntax

css
/* Keyword value */
-webkit-line-clamp: none;

/* <integer> values */
-webkit-line-clamp: 3;
-webkit-line-clamp: 10;

/* Global values */
-webkit-line-clamp: inherit;
-webkit-line-clamp: initial;
-webkit-line-clamp: revert;
-webkit-line-clamp: revert-layer;
-webkit-line-clamp: unset;

Values

none

This value specifies that the content won't be clamped.

<integer>

This value specifies the number of lines after which the content will be clamped. It must be greater than 0.

Formal definition

Initial valuenone
Applies toall elements
Inheritedno
Computed valueas specified
Animation typeby computed value type

Formal syntax

-webkit-line-clamp = 
none |
<integer [1,∞]>

Examples

Truncating a paragraph

HTML

html
<p>
  In this example the <code>-webkit-line-clamp</code> property is set to
  <code>3</code>, which means the text is clamped after three lines. An ellipsis
  will be shown at the point where the text is clamped.
</p>

CSS

css
p {
  width: 300px;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}

Result

Specifications

Specification
CSS Overflow Module Level 4
# propdef-line-clamp

Browser compatibility

BCD tables only load in the browser

See also