CSS Text Truncation: Single-Line Ellipsis and Multi-Line Clamp

PublishedToolCSS Line Clamp & Text Truncate Generator

Contents
  1. Single-Line Text Truncation: The 3 Required Properties
  2. Multi-Line Truncation (2+ Lines): WebKit Line Clamp
  3. The 3 Bugs You'll Hit in Real Projects, and How to Fix Them
  4. Single-Line vs Multi-Line Truncation CSS Comparison
  5. Wrapping Up
  6. Frequently Asked Questions

When you build a web page or mobile app UI, card titles and list previews often spill out of the space you gave them. Trimming the overflow and appending an ellipsis (...) so the layout holds together is a must-have front-end technique that makes or breaks how polished a UI feels.

Summary ① Single-line truncation: white-space: nowrap, overflow: hidden, and text-overflow: ellipsis must all be used together. Any one missing and it won't work. ② Multi-line truncation: combine display: -webkit-box, -webkit-line-clamp: N, -webkit-box-orient: vertical, and overflow: hidden. ③ Broken Flexbox parent: when truncation fails inside a flex container and the text pushes right through the parent, declaring min-width: 0 on the flex item fixes it immediately.

Single-Line Text Truncation: The 3 Required Properties

To limit text to exactly one line and turn the overflow into an ellipsis, you need to declare these three properties on the same element.

.single-line-truncate {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

Each property does its own job, and if even one is missing, no ellipsis appears.

  1. white-space: nowrap: Forces the text to stay on one line instead of wrapping, even when it's wider than the parent.
  2. overflow: hidden: Hides the text that spills outside the box width.
  3. text-overflow: ellipsis: Renders the three-dot (...) glyph in place of the text that overflow: hidden cut off.

One thing to watch: inline tags like <span> and <a> (display: inline) have no concept of width, so you must also set display: block or display: inline-block.

Multi-Line Truncation (2+ Lines): WebKit Line Clamp

When you want to show only two or three lines of a card summary or news preview and hide the rest behind an ellipsis, use the -webkit-line-clamp property.

.multi-line-truncate {
  display: -webkit-box;
  -webkit-line-clamp: 3; /* desired max line count */
  -webkit-box-orient: vertical;
  overflow: hidden;
}

People used to count characters with JavaScript or hack together pseudo-element (::after) tricks to fake multi-line truncation. Today every modern browser (Chrome, Safari, Edge, Firefox) officially supports the WebKit vendor prefix, so four lines of CSS handle it cleanly.

  • display: -webkit-box: Groups the text into a multi-line box model, creating the special box context needed to count lines.
  • -webkit-line-clamp: 3: Limits the visible text to a maximum of 3 lines.
  • -webkit-box-orient: vertical: Locks the content flow inside the box to the vertical direction.
  • overflow: hidden: Hides whatever text goes past the line count you set.

The 3 Bugs You'll Hit in Real Projects, and How to Fix Them

Here are the three most common reasons truncation code produces no ... or blows up your layout in real front-end work — and how to fix each one.

1. Text Pushes Through the Parent Inside a Flexbox / Grid Container

When the parent is display: flex and you apply truncation to the child text, the text won't shrink. Instead, it keeps stretching the parent box wider and wider.

  • Cause: Per the CSS Flexbox spec, a flex item's min-width defaults to auto (the content's minimum intrinsic width), not 0.
  • Fix: Explicitly declare min-width: 0; on the flex item with the truncation (or on its direct flex child), and truncation works normally within the parent's width.

2. It Doesn't Work on Inline Tags (<span>, <a>)

Slap single-line truncation CSS on a <span> and nothing happens. Inline elements aren't constrained by the parent's width — they just grow to fit the text.

  • Fix: Add display: inline-block; or display: block; to that element, and add max-width: 100%; if needed.

3. The Bottom of the Last Line Gets Cut Off

Set a fixed height (height: 60px) and apply -webkit-line-clamp, and the line height (line-height) won't line up with those pixels. The bottom of the third line can get sliced off like a knife cut.

  • Fix: Remove the fixed height and let the natural multiple of -webkit-line-clamp and line-height determine the height, or give it breathing room with max-height.

To choose your line count and instantly generate and copy single-line or 2–5 line clamp CSS, give the CSS Line Clamp & Text Truncate Generator a try.

CSS Line Clamp & Text Truncate Generator

Free · instantly copy one-line and 2–5 line line-clamp CSS

Single-Line vs Multi-Line Truncation CSS Comparison

ItemSingle-line truncationMulti-line truncation
Core displaydisplay: block or inline-blockdisplay: -webkit-box
Line-break controlwhite-space: nowrap-webkit-box-orient: vertical
Line limitFixed at 1 line-webkit-line-clamp: N
Overflow hidingoverflow: hiddenoverflow: hidden
Ellipsis propertytext-overflow: ellipsisBuilt into -webkit-line-clamp
Browser supportNearly all browsers, including IE6Modern browsers

Wrapping Up

Single-line truncation comes down to three properties working together: white-space: nowrap, overflow: hidden, and text-overflow: ellipsis.

For two or more lines, use the four-property WebKit set led by -webkit-line-clamp. And whenever text spills out inside a Flexbox or Grid layout, the first thing to check during real-world debugging is whether the flex item has min-width: 0 declared.

CSS Line Clamp & Text Truncate Generator

Free · instantly copy one-line and 2–5 line line-clamp CSS

Frequently Asked Questions

Why do I still need the -webkit- prefix in 2026?

The W3C's official CSS Overflow Module Level 3 spec does define a standard line-clamp property. But for backward compatibility with the existing web ecosystem, browser vendors (Chromium, WebKit, Gecko) unanimously adopted the -webkit-line-clamp syntax as a standard alias and support it permanently.

In Flexbox, which tag do I put min-width: 0 on?

If the element with the truncation class is a direct child of the flex container (a flex item), put min-width: 0 on that element itself. If there's a wrapper <div> inside the flex child and a <p> tag inside that, you need to put min-width: 0 on the outermost wrapper that acts as the flex item so the parent's flex width constraint carries down correctly.

Why is CSS truncation better than cutting text by character count with JavaScript?

If you cut by character count with JavaScript — say, 20 Korean characters or 30 English characters — you can't adapt to proportional fonts (the width difference between "W" and "I") or to responsive screen widths across devices. CSS truncation, on the other hand, has the browser's rendering engine calculate the remaining space in pixels in real time, so it places the ellipsis in the best possible spot on every device.

What do I do when truncation breaks inside a table (<table>) cell?

By default, a <td> tag widens to fit its content. Set table-layout: fixed; on the table to lock the column widths, then place a <div> or <span> inside the cell and apply truncation to that. It works without breaking the table.


The CSS properties and rendering engine behavior covered in this guide are summarized from the W3C CSS Text & Overflow official specifications. Details of the rendered output may vary in legacy browsers or specialized webview environments.

This article was adapted from our Korean original. Read the Korean original

Related articles

  1. Remove duplicate lines online and sort a list without ExcelSee how duplicate line removal works: line breaks split the list, and case and whitespace options decide what counts as a duplicate. Includes sort order.
  2. Drop Cap CSS: Style the First Letter with ::first-letterLearn how CSS ::first-letter builds a drop cap, why float and line-height matter, and how each slider value maps to the CSS you get.
  3. Letter Frequency: How the Percentages Are CalculatedSee exactly what the tool counts: percentages use only the letter count, not total characters, and the case option splits the tally into 26 or 52 letters.
  4. English Plural Nouns: Rules, Exceptions, and Quick ChecksLearn how English nouns form plurals with -s, -es, -ies, and -ves, plus irregular pairs like man-men and words like sheep that never change.
  5. Extract CSS Variables: Collect Every --var Into One TableSee how a regex gathers every --variable declaration in your CSS, wherever it lives, into one searchable table you can copy as var(--name).
  6. Markdown Link Extraction: View All Links in a TableSee how [text](URL) and ![alt](URL) links differ in regex, where reference-style links and URLs with parentheses break, and how to read the results.

Related tools