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.
overflow property does and why it
matters for layout control
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.
<!-- 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>
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-*.
<body> to stop an unwanted sideways page
scroll.
<!-- 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:
h-36 overflow-y-auto
— a fixed-height scrollable list:
h-20 overflow-hidden
— clipping content that's taller than its box:
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.
white-space: nowrap; overflow: hidden; text-overflow:
ellipsis;
— forces text onto a single line with a trailing "…".
text-overflow: ellipsis — pair it
manually with overflow-hidden and
whitespace-nowrap.
<!-- 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>
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.
overflow-x-auto +
whitespace-nowrap lets a
tab bar scroll sideways on small screens instead of wrapping.
overflow-y-auto keeps new
messages scrollable without resizing the page.
max-h-[80vh] +
overflow-y-auto lets long
modal content scroll while header/footer stay pinned.
overflow-x-auto on a
<pre> tag stops
long lines of code from breaking the page layout.
overflow-hidden +
object-cover crops an
image to fill a fixed-size box cleanly.
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 |
- 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, andclip. -
Directional control with
overflow-x-*andoverflow-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:
truncatefor 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.
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.
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-auto lets the browser decide: scrollbars only appear when content genuinely overflows. This is almost always the better default for panels, modals, and sidebars.
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.
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.
Rate Us on Google
Join Our Learning Community
Connect with thousands of learners, get daily tips, ask questions and stay updated with new tutorials.