line-clamp
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
/* 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
Formal definition
| Initial value | none |
|---|---|
| Applies to | Block containers except multi-column containers |
| Inherited | no |
| Computed value | as specified |
| Animation type | an integer |
Formal syntax
line-clamp =
none |
[ <integer [1,∞]> || <'block-ellipsis'> ] -webkit-legacy?
<block-ellipsis> =
no-ellipsis |
auto |
<string>
Examples
>Truncating a paragraph
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
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
Loading…