Skip to content

Tailwind Overflow Utilities

Overflow utilities control what happens when content is too large for its container: clip it, scroll it, or let it spill out. This lesson covers every overflow value and the per-axis variants.

What Are Overflow Utilities?

Overflow utilities map to the CSS overflow property (and its overflow-x/overflow-y axis-specific variants), controlling how a container handles child content that exceeds its bounds.

They're essential for scrollable containers, text truncation, image cropping, and preventing layout-breaking content overflow in cards and modals.

<div class="h-32 overflow-y-auto rounded-lg border p-4">
  <p>Long content that exceeds the fixed height will scroll vertically instead of overflowing the box.</p>
</div>

overflow-y-auto shows a scrollbar only when content actually exceeds the fixed h-32 height.

Overflow Utility Syntax

class="overflow-auto | overflow-hidden | overflow-visible | overflow-scroll"
class="overflow-x-auto | overflow-y-auto"
  • overflow-hidden clips content that exceeds the container, with no scrollbar.
  • overflow-auto shows a scrollbar only when content actually overflows.
  • overflow-scroll always shows scrollbars, even when content fits.
  • Add -x or -y to control just the horizontal or vertical axis independently.

Overflow Utilities Cheatsheet

Every overflow value, including per-axis variants.

Class CSS Behavior
overflow-visible overflow: visible Content spills outside the container (default)
overflow-hidden overflow: hidden Clips overflowing content, no scrollbar
overflow-auto overflow: auto Scrollbar appears only if needed
overflow-scroll overflow: scroll Scrollbar always shown on both axes
overflow-x-auto overflow-x: auto Horizontal scroll only when needed
overflow-y-auto overflow-y: auto Vertical scroll only when needed
overflow-x-hidden overflow-x: hidden Clips horizontal overflow only
overflow-clip overflow: clip Similar to hidden, disallows scroll programmatically too
overscroll-contain overscroll-behavior: contain Prevents scroll chaining to parent page

Building Scrollable Containers

Fixing a height or max-height and pairing it with overflow-y-auto is the standard Tailwind pattern for scrollable panels like chat windows, dropdown lists, or modal bodies.

<ul class="max-h-64 overflow-y-auto divide-y rounded-lg border">
  <li class="p-3">Item 1</li>
  <li class="p-3">Item 2</li>
  <li class="p-3">Item 3</li>
  <!-- more items -->
</ul>

Horizontal Scroll Rows

overflow-x-auto combined with flex and whitespace-nowrap (or fixed-width children) creates a simple horizontally scrolling row, commonly used for tag lists, image carousels, and mobile-friendly tables.

<div class="flex gap-4 overflow-x-auto pb-2">
  <img class="h-32 w-48 flex-none rounded-lg" src="/photo1.jpg" alt="" />
  <img class="h-32 w-48 flex-none rounded-lg" src="/photo2.jpg" alt="" />
  <img class="h-32 w-48 flex-none rounded-lg" src="/photo3.jpg" alt="" />
</div>

flex-none keeps each image at its own fixed width so the row can scroll instead of wrapping.

Clipping Content With overflow-hidden

overflow-hidden is frequently combined with rounded-* to properly clip a child image or background to rounded corners, since border-radius alone doesn't clip child element content.

<div class="h-40 w-40 overflow-hidden rounded-full">
  <img class="h-full w-full object-cover" src="/avatar.jpg" alt="Profile" />
</div>

Without overflow-hidden, the square image would poke out past the rounded corners of its container.

Common Mistakes

  • Applying rounded-full to a container without overflow-hidden, so the child image ignores the rounded corners.
  • Using overflow-scroll when overflow-auto was intended, causing scrollbars to show even when content fits.
  • Forgetting to set a fixed height or max-h-* before adding overflow-y-auto, which does nothing without a height constraint.
  • Not adding overscroll-contain on modal or drawer content, causing background page scroll chaining on mobile.
  • Using overflow-hidden on a parent that also needs to show a dropdown or tooltip, accidentally clipping it.

Key Takeaways

  • Overflow utilities control how a container handles content that exceeds its bounds.
  • overflow-auto shows scrollbars only when needed; overflow-scroll always shows them.
  • Per-axis utilities (overflow-x-*, overflow-y-*) let you control each direction independently.
  • overflow-hidden is required alongside border-radius to properly clip child content.
  • Scrollable containers need both a height/max-height constraint and an overflow utility to work.

Pro Tip

When a rounded avatar or thumbnail image "ignores" its rounded corners, the fix is almost always adding overflow-hidden to its direct parent container.