GO-Ve01
ServicesDevelopersBooksDictionaryPapersWikidataEncyclopediaSearchBabelCareersDeck

`line-clamp` CSS property

The line-clamp CSS property allows limiting of the contents of a block to the specified number of lines. Optionally, it also allows inserting content into the last line to indicate that content was truncated.

The **`line-clamp`** [CSS](/docs/Web/CSS) property allows limiting of the contents of a block to the specified number of lines. Optionally, it also allows inserting content into the last line to indicate that content was truncated.

## Syntax

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

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

/* <integer> and <'block-ellipsis'> values */
line-clamp: 3 no-ellipsis;
line-clamp: 10 "… (there is extra content)";

/* <'block-ellipsis'> value only */
line-clamp: no-ellipsis;
line-clamp: "… (there is extra content)";

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

### Values

This property is specified as one or two space-separated values from the following list:

- `none`
- : Specifies that content is not clamped. This keyword cannot be combined with the other values. This is the default.
- integer
- : Specifies the number of lines after which content is clamped. It must be greater than 0.
- `<’block-ellipsis’>`
- : Specifies the content inserted into the last line. It can take one of the following values:
- `no-ellipsis`: No ellipsis (character U+2026) is added if the text is truncated due to the number of line specified.
- `auto`: Renders an ellipsis character (U+2026) if the text is truncated.
- string: Renders the specified string at the end of the affected line. Browsers may truncate this string if it is very long. An empty string behaves like the `no-ellipsis` value.

> [!NOTE]
> If `<’block-ellipsis’>` is specified without an `<integer>`, it applies only when content is clamped by the height of the container.

## Description

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]
> 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.

## Formal definition

## Formal syntax

## Examples

### Truncating content with an ellipsis or a custom string

In this example, there are three cards, each with a different `line-clamp` value:

- The first has only an `<integer>` to restrict the number of lines.
- The second has an `<integer>` and the `no-ellipsis` value.
- The third has an `<integer>` and a custom `<string>`.

#### HTML

```html
<section>
<div class="card">
<h2>number of lines</h2>
<p class="integer">
In this card, the <em>number of lines</em> is specified by an
<code>&lt;integer&gt;</code>. Any content that does not fit is truncated
and an ellipsis is shown.
</p>
</div>
<div class="card">
<h2>no ellipsis</h2>
<p class="no-ellipsis">
In this card, an <code>&lt;integer&gt;</code> and a
<em>no-ellipsis</em> value are specified. Any content that does not fit is
truncated and no ellipsis is shown.
</p>
</div>
<div class="card">
<h2>custom string</h2>
<p class="string">
In this card, an <code>&lt;integer&gt;</code> and a <em>string</em> value
are specified. Any content that does not fit is truncated and the custom
string is shown instead of an ellipsis.
</p>
</div>
</section>
```

#### CSS

```css hidden
/* layout for the cards */
section {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 0.5rem;
justify-content: space-between;
}
em {
color: tomato;
}
.card {
padding: 0.2rem;
border: 1px solid tomato;
border-radius: 0.2rem;
max-width: 250px;
}
```

```css
.integer {
line-clamp: 2;
overflow: hidden;
}
.no-ellipsis {
line-clamp: 2 no-ellipsis;
overflow: hidden;
}
.string {
line-clamp: 2 "… (my custom text)";
overflow: hidden;
}
```

#### Result

100%

### Truncating a paragraph with the legacy property

This example uses the legacy `-webkit-line-clamp` property with `display` set to `-webkit-box`.

> [!NOTE]
> When using the legacy `-webkit-line-clamp` property, you will also want to set overflow to `hidden`, otherwise the content is not clipped, although an ellipsis is still shown after the specified number of lines.

#### 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

100%

## Specifications

## Browser compatibility

## See also

- [Line Clampin' (Truncating Multiple Line Text)](https://css-tricks.com/line-clampin/)

source: MDN Web Docs mirror · page

Cite this

"`line-clamp` CSS property". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/line-clamp

JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy

Save to pass ·