line-clamp CSS property

Limited availability

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

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

Note: For legacy support, the vendor-prefixed -webkit-line-clamp property 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 these prefixed properties being deprecated, the co-dependency of these three properties is a 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.

Syntax

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

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

/* Global values */
line-clamp: inherit;
line-clamp: initial;
line-clamp: revert;
line-clamp: revert-layer;
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 toBlock containers except multi-column containers
Inheritedno
Computed valueas specified
Animation typean integer

Formal syntax

line-clamp = 
none |
[ <integer [1,∞]> || <'block-ellipsis'> ] -webkit-legacy?

<integer> =
<number-token>

<block-ellipsis> =
no-ellipsis |
auto |
<string>

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

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
line-clamp
Chrome – Full support
Chrome 6 (Release date: 2010-09-02)
prefix , footnote
prefix Implemented with the vendor prefix: -webkit-
footnote See bug 40336192
Edge – Full support
Edge 17 (Release date: 2018-04-30)
prefix
prefix Implemented with the vendor prefix: -webkit-
Firefox – Full support
Firefox 68 (Release date: 2019-07-09)
prefix
prefix Implemented with the vendor prefix: -webkit-
Opera – Full support
Opera 15 (Release date: 2013-07-02)
prefix , footnote
prefix Implemented with the vendor prefix: -webkit-
footnote See bug 40336192
Safari – No support
Safari 18.2 – 18.3 (Release date: 2024-12-11)
footnote Removed in 18.4 and later
footnote Accidental exposure.
Safari – Full support
Safari 5 (Release date: 2010-06-07)
prefix
prefix Implemented with the vendor prefix: -webkit-
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
prefix , footnote
prefix Implemented with the vendor prefix: -webkit-
footnote See bug 40336192
Firefox for Android – Full support
Firefox for Android 68 (Release date: 2019-07-09)
prefix
prefix Implemented with the vendor prefix: -webkit-
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
prefix , footnote
prefix Implemented with the vendor prefix: -webkit-
footnote See bug 40336192
Safari on iOS – No support
Safari on iOS 18.2 – 18.3 (Release date: 2024-12-11)
footnote Removed in 18.4 and later
footnote Accidental exposure.
Safari on iOS – Full support
Safari on iOS 4.2 (Release date: 2010-11-22)
prefix
prefix Implemented with the vendor prefix: -webkit-
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
prefix , footnote
prefix Implemented with the vendor prefix: -webkit-
footnote See bug 40336192
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
prefix , footnote
prefix Implemented with the vendor prefix: -webkit-
footnote See bug 40336192
WebView on iOS – No support
WebView on iOS 18.2 – 18.3 (Release date: 2024-12-11)
footnote Removed in 18.4 and later
footnote Accidental exposure.
WebView on iOS – Full support
WebView on iOS 4.2 (Release date: 2010-11-22)
prefix
prefix Implemented with the vendor prefix: -webkit-
none
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – Full support
Firefox 68 (Release date: 2019-07-09)
footnote Full support
Opera – No support
Opera
footnote No support
Safari – Full support
Safari 18.2 (Release date: 2024-12-11)
footnote Full support
Chrome Android – No support
Chrome Android
footnote No support
Firefox for Android – Full support
Firefox for Android 68 (Release date: 2019-07-09)
footnote Full support
Opera Android – No support
Opera Android
footnote No support
Safari on iOS – Full support
Safari on iOS 18.2 (Release date: 2024-12-11)
footnote Full support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – Full support
WebView on iOS 18.2 (Release date: 2024-12-11)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.
Requires a vendor prefix or different name for use.
Has more compatibility info.

See also