Boneyard Tools

CSS Line Clamp Generator

Truncate text after a chosen number of lines and add a trailing ellipsis with pure CSS, no JavaScript. Set the line count from 1 to 10, watch a live preview clamp a sample paragraph, and copy the ready -webkit-line-clamp rule. Picking a single line also appends a commented white-space alternative that is simpler for the one-line case.

How to generate line clamp CSS

  1. Set the Lines field to how many lines of text to keep before truncating (1 to 10).
  2. Check the live preview panel, which clamps a sample paragraph at your chosen count.
  3. Read the generated CSS in the code box below the preview.
  4. Click Copy and paste the rule onto your text container.

Examples

Clamp to three lines

lines 3
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;

Single line with the commented alternative

lines 1
display: -webkit-box;
-webkit-line-clamp: 1;
-webkit-box-orient: vertical;
overflow: hidden;

/* One-line alternative without -webkit-box:
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
*/

Frequently asked questions

What exactly does the generated CSS contain?

Four declarations: display: -webkit-box, -webkit-line-clamp with your line count, -webkit-box-orient: vertical, and overflow: hidden. Together they cap the visible lines and let the browser add the ellipsis. Choosing one line appends a commented white-space alternative underneath.

How does multi-line clamping work?

The container is laid out as a vertical -webkit-box, the line-clamp value limits how many lines render, and overflow: hidden trims the rest. When text is cut, the browser draws a trailing ellipsis automatically, so you never add one by hand.

Is -webkit-line-clamp widely supported?

Yes. Despite the -webkit- prefix it is honoured across current Chrome, Safari, Edge and Firefox, and the prefixed form is still the standard way to clamp multiple lines. It is a well established technique rather than an experimental one.

Why is there a separate one-line option?

A single line does not need the box model at all. white-space: nowrap with overflow: hidden and text-overflow: ellipsis is shorter and more predictable, so the tool adds that as a commented block whenever you set the count to 1.

What line counts can I choose?

The Lines field accepts whole numbers from 1 to 10 through its stepper. The underlying engine will clamp to any integer of 1 or more, but the interface caps the control at 10, which covers almost every card, list and preview layout.

Does the element need a fixed height?

No. Clamping works by line count, not by a pixel height, so the box grows to fit up to the chosen number of lines and hides anything beyond. This makes it robust across different font sizes and line heights without hard-coding a height.

Why is my text not truncating?

The most common causes are a missing display: -webkit-box, a container that is wide enough to fit all the text on fewer lines, or a child element that breaks the box formatting. Apply the rule to the element that directly holds the text and avoid overriding overflow elsewhere.

Can I change the ellipsis character?

Not through this technique. The trailing ellipsis is drawn by the browser and is not styleable, so the output is a standard three-dot ellipsis. If you need a custom marker you would have to measure and truncate the text with JavaScript instead.

Is anything sent to a server?

No. The CSS is generated in your browser as you change the line count, and your settings are never uploaded.

Learn more

Related tools