CSS Line Clamp Generator

Truncate text after any number of lines with a clean ellipsis. Adjust the line count, preview it live, and copy ready-to-use CSS or Tailwind classes.

What Is CSS Line Clamp?

Line clamp is the common name for a CSS technique that truncates a block of text after a fixed number of lines and adds an ellipsis at the cut-off point. It solves something text-overflow: ellipsis alone cannot: truncating after several lines instead of just one. It's the standard pattern behind card previews, blog excerpts, and product descriptions where every tile needs to stay the same height no matter how much text a given item actually has.

-webkit-line-clamp Syntax

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

  • display: -webkit-box: line clamp only works on this legacy box display mode. Without it, the property is silently ignored.
  • -webkit-box-orient: vertical: stacks the box content vertically, which line-clamp needs to count lines correctly.
  • -webkit-line-clamp: N: the number of lines to show before truncating.
  • overflow: hidden: hides the text that falls past the line limit.
  • text-overflow: ellipsis: adds the trailing "…" character at the cut-off point.

Do You Still Need the -webkit- Prefix?

Yes, for now. Despite the vendor prefix, -webkit-line-clamp has broad real-world support across current Chrome, Edge, Firefox, Safari, and Samsung Internet, so it remains the safe, universal choice for line clamping today. The unprefixed line-clamp property defined in the CSS Overflow Module Level 4 spec is newer and still rolling out inconsistently across browsers, so treat it as a forward-compatible addition alongside the prefixed version, not a replacement for it. Including both in the same rule, as this generator does, costs nothing and covers every browser your visitors are likely using.

Tailwind CSS Line Clamp

Tailwind has shipped line-clamp-{n} utilities in core since v3.3, so no plugin is required on any current version, including v4. Use line-clamp-1 through line-clamp-6 directly, or an arbitrary value like line-clamp-[8] for anything beyond the default scale. Add a breakpoint variant such as md:line-clamp-none to remove the clamp entirely on larger screens.

<p class="line-clamp-3">...</p>

<p class="line-clamp-3 md:line-clamp-none">...</p>

Common Line Clamp Use Cases

Card Grid Previews

.card-description { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }

Blog Post Excerpts

.post-excerpt { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }

Product Descriptions

.product-summary { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 4; overflow: hidden; }

User Comments

.comment-body { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 5; overflow: hidden; }

Common Mistakes

  • Using text-overflow: ellipsis alone: this only works with white-space: nowrap on a single line. It has no effect across multiple lines without the -webkit-box display mode.
  • Forgetting -webkit-box-orient: vertical: without it, -webkit-line-clamp is ignored even when every other property is set correctly.
  • Applying line clamp to an inline element: the target needs display: -webkit-box (or -webkit-inline-box in inline contexts), not the default inline or block display.
  • Expecting the hidden text to be removed from the DOM: line clamp only hides overflow visually. The full text stays present for screen readers and search engines.

How to Use This Generator

  1. Choose a Preview tab: Card, Blog Excerpt, Product, or Comment
  2. Edit the Preview Text box to test your own content
  3. Adjust Number of Lines, Font Size, Line Height, and Container Width
  4. Pick CSS or Tailwind as your output format
  5. Click Copy Code to copy the result, or Copy Shareable Link to save your exact settings

Frequently Asked Questions

What does -webkit-line-clamp do in CSS?

It limits a block of text to a fixed number of visible lines and adds an ellipsis where the text is cut off, hiding everything past that line count.

Do I need -webkit-box-orient and display: -webkit-box for line clamp to work?

Yes. -webkit-line-clamp only takes effect on an element with display: -webkit-box and -webkit-box-orient: vertical. Without both, the browser ignores the property.

Can I use line-clamp without the -webkit- prefix?

An unprefixed line-clamp property exists in the CSS Overflow Module Level 4 spec, but support is still inconsistent across browsers. Keep the -webkit- prefixed version in your CSS for now and add the unprefixed property alongside it as a forward-compatible extra, not a replacement.

Why doesn't text-overflow: ellipsis work on its own for multiple lines?

text-overflow: ellipsis is designed for single-line truncation and requires white-space: nowrap. Multi-line truncation needs the -webkit-line-clamp property and its supporting box properties instead.

How do I truncate text after N lines in Tailwind CSS?

Add a line-clamp utility class such as line-clamp-3 directly to the element. This has been built into Tailwind's core since v3.3, so no plugin or config change is needed.

What happens if my text is shorter than the line limit?

Nothing changes. Line clamp only affects text that actually overflows the given number of lines, so shorter text displays in full with no ellipsis.