Ch 10 / 45
Chapter 10 Beginner 4 min read Tailwind CSS

Overflow in Tailwind CSS

By default, content that's too big for its container spills right out and breaks your layout — a tall paragraph pokes out of a card, or a wide table pushes the whole page sideways. Tailwind's overflow utilities give you full control over what happens when content doesn't fit: clip it, scroll it, or let it spill freely. In this chapter you'll learn every overflow value, how to control the x and y axes independently, and how to pair overflow with truncation and line-clamping for clean, predictable UIs.

Advertisement
Google Ad Placeholder · 728×90 Leaderboard
What you'll learn
What the CSS overflow property does and why it matters for layout control
The five core overflow values — visible, hidden, scroll, auto and clip
Controlling horizontal & vertical overflow independently with overflow-x / overflow-y
Building real scrollable UI — card filmstrips, chat panels, modal bodies
Truncating text with truncate, text-ellipsis, and multi-line line-clamp
Common overflow patterns used in real production interfaces

What is Overflow in Tailwind CSS?

The CSS overflow property tells the browser what to do when a child element's content is bigger than the box that contains it. Tailwind exposes this directly as utility classes — instead of writing overflow: hidden; in a stylesheet, you add overflow-hidden straight to the element's class list.

Overflow only becomes visible once a box has a constrained size — a fixed height, a max-w-*, or content inside a flex/grid item that's been squeezed. Without a size constraint, a block element simply grows to fit its content and there's nothing to overflow.

Default overflow vs overflow-hidden
<!-- No overflow class — content spills out of the fixed-height box -->
<div class="h-24 w-64 bg-white rounded-lg p-3 border border-gray-200">
  This paragraph has more text than the 96px-tall box can hold, so it
  overflows the boundary and bleeds into whatever sits below it.
</div>

<!-- overflow-hidden — anything outside the box is clipped away -->
<div class="h-24 w-64 overflow-hidden bg-white rounded-lg p-3 border border-gray-200">
  This paragraph has more text than the 96px-tall box can hold, but this
  time the extra content is simply cut off at the box's edge.
</div>
visible
Default behaviour. Content isn't clipped — it can spill outside the box in any direction.
hidden
Clips anything outside the box. No scrollbars — the extra content is simply not shown.
scroll
Always shows scrollbars on both axes, even when the content actually fits inside the box.
auto
The browser decides — scrollbars appear only when content actually overflows the box.
Note Tailwind also ships overflow-clip, which behaves like hidden but additionally disables the box's ability to become a scroll container via JavaScript. Use it when content should be clipped and never scrollable by any means.

All Overflow Values at a Glance

Every overflow utility maps one-to-one to the CSS overflow property. Here's every value Tailwind ships, side by side.

Class CSS Equivalent Behaviour
overflow-visible overflow: visible Default. Content can spill outside the box.
overflow-hidden overflow: hidden Clips overflowing content — no scrollbars appear.
overflow-clip overflow: clip Like hidden, but also blocks programmatic scrolling.
overflow-scroll overflow: scroll Always-visible scrollbars on both axes.
overflow-auto overflow: auto Scrollbars appear only when content overflows.

In practice, overflow-auto and overflow-hidden cover the vast majority of real-world cases — auto for scrollable panels, hidden for clipping images and keeping rounded corners clean.

Overflow-X & Overflow-Y — Directional Control

Sometimes you only want to control one axis — let a filmstrip of cards scroll horizontally while the height stays fixed, or let a sidebar scroll vertically while its width never changes. Tailwind splits overflow into per-axis utilities: overflow-x-* and overflow-y-*.

Directional overflow classes — a quick reference
overflow-x-auto
A horizontal scrollbar appears only when content is wider than the box. Vertical overflow behaviour is untouched.
overflow-x-hidden
Clips horizontal overflow — commonly applied to <body> to stop an unwanted sideways page scroll.
overflow-x-scroll
Always shows a horizontal scrollbar, even if the content already fits.
overflow-y-auto
A vertical scrollbar appears only when content is taller than the box — the classic "scrollable panel" pattern.
overflow-y-hidden
Clips vertical overflow while leaving horizontal overflow behaviour completely untouched.
overflow-y-scroll
Always reserves space for a vertical scrollbar, which prevents layout shift as content length changes.
Independent x/y overflow control
<!-- Horizontal-only scroll: a filmstrip of cards -->
<div class="flex gap-4 overflow-x-auto overflow-y-hidden pb-2">
  <div class="shrink-0 w-40 h-24 bg-cyan-500 rounded-lg"></div>
  <div class="shrink-0 w-40 h-24 bg-purple-500 rounded-lg"></div>
  <div class="shrink-0 w-40 h-24 bg-orange-500 rounded-lg"></div>
</div>

<!-- Vertical-only scroll: a fixed-height chat panel -->
<div class="h-56 overflow-y-auto overflow-x-hidden space-y-2 p-3 bg-gray-50 rounded-lg">
  <div class="bg-white p-3 rounded-lg shadow-sm">Message one</div>
  <div class="bg-white p-3 rounded-lg shadow-sm">Message two</div>
  <div class="bg-white p-3 rounded-lg shadow-sm">Message three</div>
</div>

Live Examples — See Overflow in Action

These boxes are rendered with real Tailwind utility classes right on this page — scroll inside them to feel the difference between each overflow value.

flex gap-3 overflow-x-auto — a horizontal filmstrip. Drag or scroll sideways:

Live Preview
Card 1
Card 2
Card 3
Card 4
Card 5

h-36 overflow-y-auto — a fixed-height scrollable list:

Live Preview
Notification one — task assigned
Notification two — comment added
Notification three — deploy finished
Notification four — review requested
Notification five — build passed

h-20 overflow-hidden — clipping content that's taller than its box:

Live Preview

This text block is taller than its 80px-high container, but overflow-hidden clips everything past the edge so the rounded corners always stay clean and predictable.

Notice how the third example keeps its rounded corners intact — pairing relative + overflow-hidden on a parent is also the standard way to crop images and avatars in Tailwind.

Overflow + Text — Truncate & Line-Clamp

Overflow utilities pair naturally with text-clipping helpers when you need single-line ellipsis truncation or multi-line clamping — essential for card titles, table cells, and blog excerpts that must stay a predictable height.

Text overflow helpers
truncate
Shorthand for white-space: nowrap; overflow: hidden; text-overflow: ellipsis; — forces text onto a single line with a trailing "…".
text-ellipsis
Sets only text-overflow: ellipsis — pair it manually with overflow-hidden and whitespace-nowrap.
text-clip
Default. Clips text exactly at the container edge with no ellipsis character shown.
line-clamp-2 / line-clamp-3
Clips text after N lines and appends an ellipsis — perfect for card descriptions and blog excerpts.
line-clamp-none
Removes any line-clamp restriction, letting text flow to its natural length again.
Single-line truncate vs multi-line line-clamp
<!-- Single-line truncation with an ellipsis -->
<h3 class="truncate w-48 font-semibold">
  This heading is way too long to fit in 192px
</h3>

<!-- Multi-line clamp — perfect for card descriptions -->
<p class="line-clamp-3 text-sm text-gray-500">
  Tailwind's line-clamp utilities cut text off after a set number of lines
  and append an ellipsis, so every card in a grid keeps the same height no
  matter how long the underlying content actually is.
</p>
Tip line-clamp-* relies on the -webkit-box display model internally — Tailwind adds display: -webkit-box; -webkit-box-orient: vertical; automatically, so you never need to write that CSS yourself.

Common Real-World Use Cases

Overflow utilities show up everywhere in production UI. Here are the patterns you'll reach for most often.

Horizontal Tab / Nav Scroll
overflow-x-auto + whitespace-nowrap lets a tab bar scroll sideways on small screens instead of wrapping.
Chat / Message Panels
A fixed-height container with overflow-y-auto keeps new messages scrollable without resizing the page.
Modal / Dialog Body
max-h-[80vh] + overflow-y-auto lets long modal content scroll while header/footer stay pinned.
Code Block Scroll
overflow-x-auto on a <pre> tag stops long lines of code from breaking the page layout.
Image Thumbnail Crop
overflow-hidden + object-cover crops an image to fill a fixed-size box cleanly.
Custom Dropdown Menus
max-h-60 + overflow-y-auto keeps a long options list scrollable inside the dropdown panel.

Quick Reference — Overflow Classes

Class CSS Equivalent Description
overflow-visible overflow: visible Default — content spills outside the box
overflow-hidden overflow: hidden Clips overflowing content, no scrollbars
overflow-clip overflow: clip Clips content, blocks programmatic scroll too
overflow-scroll overflow: scroll Scrollbars always visible on both axes
overflow-auto overflow: auto Scrollbars appear only when needed
overflow-x-auto overflow-x: auto Horizontal-only scroll, as needed
overflow-y-auto overflow-y: auto Vertical-only scroll, as needed
overflow-x-hidden overflow-x: hidden Clips horizontal overflow only
overflow-y-hidden overflow-y: hidden Clips vertical overflow only
truncate overflow: hidden; text-overflow: ellipsis; … Single-line text truncation with ellipsis
text-ellipsis text-overflow: ellipsis Ellipsis only — pair with overflow-hidden
line-clamp-2 -webkit-line-clamp: 2 Clips text after 2 lines with an ellipsis
line-clamp-none -webkit-line-clamp: unset Removes an existing line-clamp restriction
overscroll-contain overscroll-behavior: contain Stops scroll chaining into the parent page
overscroll-none overscroll-behavior: none Disables both scroll chaining and bounce/rubber-band
Featured Course
Master Tailwind CSS with Real Projects(React Course)
Go from utility-class beginner to building production-grade UIs. Our structured course covers Tailwind v4, Vite integration, custom themes, component patterns, and 5 real projects including a full SaaS landing page and dashboard.
45 Chapters 10+ Hours of Content 5 Real Projects Certificate Included Live Mentoring
🎨
⭐ 4.9 · 1,200+ students
Tailwind CSS Overflow Cheat Sheet
Download our free one-page cheat sheet covering every overflow, overflow-x/y, truncate, line-clamp, and overscroll utility class with their CSS equivalents.
Overflow Scroll Truncate Line-Clamp Overscroll Layout
Download Free Cheat Sheet
Chapter Summary
  • The overflow property controls what happens when content is bigger than its container — it only matters once a box has a constrained size.
  • The five core values are visible, hidden, scroll, auto, and clip.
  • Directional control with overflow-x-* and overflow-y-* lets you scroll one axis while clipping or fixing the other.
  • overflow-auto and overflow-hidden are the two classes you'll reach for most — scrollable panels and clean image/rounded crops, respectively.
  • Text truncation pairs with overflow: truncate for single-line ellipsis, line-clamp-* for multi-line clamping.
  • Real-world patterns include horizontal nav scroll, chat panels, modal bodies, code blocks, image crops, and dropdown menus.
  • Next chapter moves into the Flexbox & Grid group — starting with core Flexbox properties for building responsive layouts.

Quick Check — Questions & Answers

Test your understanding of this chapter. Click a question to reveal the answer.

Both visually clip content the same way. The difference is programmatic scrolling: overflow-hidden still lets JavaScript scroll the element with element.scrollTo() even though there's no visible scrollbar. overflow-clip goes further and disables that too — the box can never become a scroll container, by any means. Use clip when content must be clipped and permanently non-scrollable.
Combine overflow-x-auto (or overflow-x-scroll) with overflow-y-hidden, and lay children out with flex plus shrink-0 so they don't wrap onto new lines.

Example: <div class="flex overflow-x-auto overflow-y-hidden gap-4"> — this is exactly the pattern behind horizontal card filmstrips and scrollable tab bars.
overflow-scroll always shows scrollbars on both axes, even when the content fits perfectly and there's nothing to scroll — this can leave visible empty scrollbar tracks.

overflow-auto lets the browser decide: scrollbars only appear when content genuinely overflows. This is almost always the better default for panels, modals, and sidebars.
Use line-clamp-3 on the text element:

<p class="line-clamp-3">Long paragraph text…</p>

Tailwind sets display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; behind the scenes, so anything past the third line is clipped and an ellipsis is appended automatically.
This usually happens when a child element is wider than the viewport — an image without max-w-full, a fixed-width element, or negative margins pushing content past the edge.

The quick fix is adding overflow-x-hidden to <body> or <html>, but that only hides the symptom. The better fix is finding the oversized element and constraining it with max-w-full or w-full so the scrollbar never appears in the first place.

MCQ Quiz — Test Yourself

Select the best answer for each question. Correct answers are revealed after you click.

Question 1 of 4
Which class always shows scrollbars on both axes, even when the content already fits?
Question 2 of 4
Which class clips overflowing content AND prevents the element from being scrolled programmatically with JavaScript?
Question 3 of 4
Which class combination creates a horizontal-only scrolling filmstrip of cards?
Question 4 of 4
Which class clips a paragraph to exactly 2 lines and adds a trailing ellipsis?

Rate Us on Google

4.8 / 5
Enjoying this tutorial?
Your 5-star review helps other learners discover our free tutorials and encourages us to keep creating quality content.
80+ reviews
Write a Google Review
Join WhatsApp Channel