CSS Text Overflow: Ellipsis, Line Clamp and Word Breaking
Long content escapes its box when the box is too small. overflow decides what happens to the excess: visible, hidden, clip, scroll or auto. For one line ending in dots, combine white-space: nowrap, overflow: hidden and text-overflow: ellipsis. For several lines use -webkit-line-clamp. To split unbreakable words, use overflow-wrap: anywhere.
| Problem | CSS | Tailwind |
|---|---|---|
| One line, cut with dots | white-space: nowrap; overflow: hidden; text-overflow: ellipsis | truncate |
| Three lines, then dots | display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden | line-clamp-3 |
| Long URL breaks the layout | overflow-wrap: anywhere | wrap-anywhere (v4.1) or break-words |
| Box needs its own scrollbar | overflow: auto | overflow-auto |
Updated
Drag the width slider and the sample box shrinks around a real web address, the word Donaudampfschifffahrtsgesellschaft and a normal sentence. Every overflow, wrapping and clamping option is a button, the result is instant, and the CSS you would need is written out underneath.
overflow values compared
| Value | Excess content | Scrollbars | Scroll container? | Tailwind |
|---|---|---|---|---|
| visible | Paints outside the box | Never | No | overflow-visible |
| hidden | Cut off at the padding edge | Never | Yes (scrollable by script) | overflow-hidden |
| clip | Cut off | Never | No | overflow-clip |
| scroll | Scrolls | Always shown | Yes | overflow-scroll |
| auto | Scrolls | Only when needed | Yes | overflow-auto |
Single-line ellipsis
The three-line ellipsis recipe
Remove any one of the three declarations and the dots disappear. The title attribute keeps the full text available.
<style>
.one-line { width: 240px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
border: 1px solid #cbd5e1; padding: 6px 8px }
</style>
<p class="one-line" title="Handmade ceramic mugs, glazed in small batches in our studio">Handmade ceramic mugs, glazed in small batches in our studio</p>Ellipsis inside a flex row
The middle item gets min-width: 0 so it may shrink below its text width. Without it the row overflows instead.
<style>
.row { display: flex; gap: 8px; align-items: center; width: 280px; border: 1px solid #cbd5e1; padding: 6px }
.name { min-width: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis }
.tag { flex: none; background: #dbeafe; padding: 2px 8px; border-radius: 99px; font-size: 12px }
</style>
<div class="row"><b>#12</b><span class="name">Quarterly-report-final-version-reviewed.pdf</span><span class="tag">PDF</span></div>Multi-line clamp
Clamp a card description to three lines
The prefixed pattern below is the widely supported one. The plain line-clamp declaration is added for browsers that already handle it.
<style>
.clamp { width: 260px; display: -webkit-box; -webkit-box-orient: vertical;
-webkit-line-clamp: 3; line-clamp: 3; overflow: hidden; line-height: 1.4 }
</style>
<p class="clamp">Our two-day pottery course covers wedging, centring and throwing on the wheel, then trimming and glazing on day two. Small groups of six, all clay and firing included, and you take home everything you make.</p>word-break vs overflow-wrap vs hyphens
| Declaration | Breaks where | Good for | Tailwind |
|---|---|---|---|
| overflow-wrap: break-word | Inside a word only if it would overflow | Body text with the odd long word | break-words |
| overflow-wrap: anywhere | Same, and allows the box to shrink | URLs in flex items and narrow columns | wrap-anywhere (v4.1) |
| word-break: break-all | Between any letters, always | Code, hashes, IDs | break-all |
| word-break: keep-all | Never inside CJK words | Chinese, Japanese, Korean | break-keep |
| hyphens: auto | At syllables, with a hyphen | Narrow or justified text with lang set | hyphens-auto |
The same URL with four break settings
Each box is 160px wide. Only the last is left to overflow.
<style>
p { width: 160px; border: 1px solid #94a3b8; padding: 4px; margin: 0 0 8px; font-size: 13px }
</style>
<p style="overflow-wrap: anywhere">anywhere: https://example.com/a-very-long-path/with-no-spaces</p>
<p style="word-break: break-all">break-all: https://example.com/a-very-long-path/with-no-spaces</p>
<p lang="de" style="-webkit-hyphens: auto; hyphens: auto">hyphens (de): Donaudampfschifffahrtsgesellschaft</p>
<p>default: https://example.com/a-very-long-path/with-no-spaces</p>Truncating table cells
Fixed table layout with ellipsis cells
table-layout: fixed makes the column widths win over the content, so the ellipsis can kick in.
<style>
table { width: 300px; table-layout: fixed; border-collapse: collapse; font-size: 13px }
td, th { border: 1px solid #cbd5e1; padding: 4px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis }
col.n { width: 40px }
</style>
<table>
<colgroup><col class="n"><col></colgroup>
<tr><th>#</th><th>Customer note</th></tr>
<tr><td>1</td><td>Please leave the parcel with the neighbour at number 14 if nobody answers</td></tr>
<tr><td>2</td><td>Gift wrap</td></tr>
</table>
The five overflow values
visible is the default and lets content paint outside the box without affecting layout around it. hidden and clip cut it at the padding edge. scroll always shows scrollbars, even when nothing overflows, and auto shows them only when needed, which is nearly always the better choice.
overflow is shorthand for overflow-x and overflow-y. Setting one axis to visible and the other to hidden does not work as written: the browser computes visible as auto in that pairing, so you may see an unexpected scrollbar. clip is the exception and can be combined with visible.
Breaking words that do not fit
overflow-wrap: break-word breaks long words when needed but does not let the box shrink below the longest word, so it can still overflow inside flex items and tables. overflow-wrap: anywhere also lowers that minimum size, which is why it fixes long URLs in narrow sidebars.
hyphens: auto inserts a hyphen at a proper syllable boundary for languages the browser supports, making justified or narrow German and Dutch text far more readable. Some Safari versions only understand -webkit-hyphens, so write both. Use hyphens: manual and the ­ soft hyphen when you want to choose the break points yourself.
Truncation and accessibility
Clipped text is still in the page, so screen readers read the whole thing, which is good. Sighted keyboard and touch users are the ones who lose out, because they cannot hover to see a tooltip.
For product names or messages that matter, offer a way to expand the text, such as a Show more button or a details element, instead of relying on the ellipsis alone. Keep line clamps for previews where the full text is one click away.
How it works
- Choose which sample text to load: a URL, a long compound word or a paragraph.
- Drag the width slider until the text no longer fits.
- Try overflow values, ellipsis, a line clamp and the word breaking options one by one.
- Copy the CSS that matches the result you like.
Tips
- Ellipsis needs all three of nowrap, overflow other than visible, and a width limit. Missing any one of them shows no dots.
- Inside a flex row, a truncated child also needs min-width: 0, because flex items refuse to shrink below their content by default.
- Put the full text in a title attribute or show it on focus, since truncation hides words from people who cannot hover.
- hyphens: auto only hyphenates when the element or a parent has a lang attribute the browser has a dictionary for.
Frequently asked questions
Why does text-overflow: ellipsis not work?
Usually one of its partners is missing. The element must be block-level or inline-block with a constrained width, have overflow set to hidden or clip, and keep the text on one line with white-space: nowrap. In a flex or grid item, also add min-width: 0 so the item is allowed to shrink.
Is line-clamp supported without the -webkit- prefix?
The prefixed form, -webkit-line-clamp together with display: -webkit-box and -webkit-box-orient: vertical, works in all current major browsers and is what Tailwind outputs. The unprefixed line-clamp property from CSS Overflow Level 4 is still rolling out, so check caniuse before relying on it alone.
What is the difference between word-break and overflow-wrap?
overflow-wrap only breaks a word when it would otherwise overflow, so normal words wrap normally. word-break: break-all lets the browser break between any two letters everywhere, which gives ragged, hard-to-read text. word-break: keep-all is for Chinese, Japanese and Korean text where you do not want breaks inside words.
What does overflow: clip do that hidden does not?
Both cut off the excess. hidden still creates a scroll container, so script can scroll it and it affects position: sticky inside. clip forbids all scrolling, and with overflow-clip-margin you can let content spill a few pixels past the edge before clipping.
How do I truncate text inside a table cell?
Set table-layout: fixed on the table and a width on the columns, then apply the usual nowrap, hidden and ellipsis trio to the cell. Without fixed layout the column simply grows to fit the text. Another option is max-width: 0 with width: 100% on the cell.
Related: CSS text styling playground, CSS box model visualiser, Flexbox and grid cheat sheet, CSS sizing functions, HTML accessibility checker.
Build your site free or see all free tools. On We.Inc you can build your site free, with no card and no trial needed to start. AI building is on paid plans from $19 a month.
More in Guides
- CSS Text Styling: Fonts, Size, Weight, Underline, Alignment
- CSS Transforms: Rotate, Scale, Translate and Skew
- CSS Transitions and Keyframes, With 20 Copyable Examples
- CSS Variables: From var() to Themes and @property
- CSS z-index and Stacking Contexts, Taken Apart in 3D
- How to Add Dark Mode to a Website (CSS, Tailwind, Next.js)
- Data Fetching in React and Next.js, Compared on One App
- Data URLs: data:text/html;base64 and Friends, Explained
Product
Who It's For
- For Agencies
- For Freelancers
- For Hosting Providers
- For SaaS Platforms
- For Startups
- For Financial Services
- For Healthcare
Features
Resources
- Blog
- Help Center
- Free Business Tools
- Free UI Components
- Website Templates
- Template Collections
- Website Examples
- Guides
- Comparisons
- Alternatives
- Best Lists
- Reviews
- Pricing Guides
- Use Cases
- Glossary & Guides
- Integrations
- Developers
- Benchmark
- Windows App