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
- Set the Lines field to how many lines of text to keep before truncating (1 to 10).
- Check the live preview panel, which clamps a sample paragraph at your chosen count.
- Read the generated CSS in the code box below the preview.
- 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
- The -webkit-line-clamp technique explained
How the four line-clamp declarations cooperate, when to use the one-line alternative, and how to avoid the common reasons text fails to truncate.
Related tools
CSS Clamp Generator
Generate a responsive CSS clamp() value for fluid font sizes and spacing. Set min and max sizes plus viewport bounds and copy the result.
Type Scale Generator
Generate a modular typographic scale from a base size and ratio. Get px and rem font sizes for every step, ready to drop into your CSS. Free and instant.
CSS Gradient Generator
Build linear and radial CSS gradients with a live preview. Pick colors, set the angle and copy ready-to-paste background code for your site.
.env to JSON
Convert a .env file to JSON, or JSON back to .env. Parses KEY=value lines, comments, quotes and export. Runs entirely in your browser.
ASCII Table
Full ASCII table for all 128 codes with decimal, hex, octal and binary values, character names and descriptions. Search by code, hex or character.
Aspect Ratio Box Generator
Generate CSS for a responsive aspect-ratio container. Use the modern aspect-ratio property or the padding-top fallback, then copy the ready code.