October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk6 min

CSS Overflow: How to Control Scrolling and Hidden Content

Choose the right CSS overflow behavior for each axis: allow content to spill, scroll only when needed, hide scrollbars, or crop content without scrolling.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use overflow: auto when a constrained box should scroll only if its content does not fit; use scroll for a scroll container even when content fits, hidden to clip while retaining programmatic scrolling, and clip for visual cropping without scrolling. The default, visible, lets content paint outside its box. The right choice depends on whether the content must remain reachable and which axis overflows.

What CSS overflow controls

The CSS Overflow Module Level 3 defines how block, flex, and grid containers handle content that extends beyond their box. The overflow shorthand sets both axes; overflow-x and overflow-y set horizontal and vertical behavior. These properties govern clipping and scrollable overflow, not the size of the box itself: a useful scroll area generally needs a constrained width, height, maximum size, or equivalent layout constraint. See the W3C CSS Overflow Module Level 3 and MDN’s overflow reference.

Value What it does Use it when
visible Does not clip; content may paint outside the box. Does not create a scroll container. Content can extend beyond the box without disrupting the layout.
auto Clips overflow and permits scrolling when needed. Scrollbars are typically shown only when content overflows. A constrained panel should scroll only when its content requires it.
scroll Creates a scroll container and requests scrollbars whether or not content overflows. Actual scrollbar presentation varies by browser and platform. Persistent scrollbar behavior is intentional.
hidden Clips content and hides scrollbars, but the box remains scrollable programmatically and may scroll to focused content. Scrolling is needed through scripts or focus navigation, but visible scrollbars are not wanted.
clip Clips at the overflow clip edge without creating a scroll container or allowing programmatic scrolling. Content is deliberately cropped and does not need to be reached.

Values other than visible and clip establish a new block formatting context. The behavior and accessibility trade-offs of each value are described in MDN’s reference.

Choose the right overflow value

Use auto for a normal scrollable panel

For content that must remain available but may exceed a panel’s size, constrain the box and use auto on the axis that should scroll. This is usually the best starting point for a panel that should not show a scrollbar unnecessarily.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use scroll only when persistent scrollbar behavior is intended

scroll requests a scrollbar even if the content currently fits. Browsers with overlay scrollbars may display that request differently, so it does not guarantee a visible, permanently occupying scrollbar on every platform. If the goal is to prevent layout shifts as a scrollbar comes and goes, consider scrollbar-gutter: stable with overflow: auto, as described in MDN’s guide to handling overflow.

Use hidden when clipping is intended but scrolling must still be possible

Although users do not see scrollbars, scripts can scroll an element with scrolling APIs, and focus navigation may bring focused content into view. Do not assume that hidden makes the clipped content unreachable.

Reserve clip for deliberate cropping

clip is not a scroll-free substitute for hidden: it does not create a scroll container and cannot be scrolled programmatically. Use it only when the cropped content is genuinely decorative or otherwise unnecessary to access.

Let content overflow with visible

The default visible value allows content to paint outside its box. That can work for intentional overlap, but it is not a way to create a scrollable area.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How to make a div scroll

First give the element a size limit so its content can exceed the box; then set the intended overflow axis. These examples cover a vertically scrolling panel, a horizontally scrolling table wrapper, and a decorative crop:

.panel {
  max-block-size: 24rem;
  overflow-y: auto;
}

.table-wrapper {
  max-width: 100%;
  overflow-x: auto;
}

.decorative-crop {
  overflow: clip;
}

A max-block-size lets a panel grow until it reaches its limit, after which vertical overflow can scroll. A maximum width similarly keeps a table wrapper within its available space. Without an effective size constraint, the box may grow with its contents instead of overflowing.

Set horizontal and vertical overflow deliberately

The shorthand accepts one value for both axes, or two values in horizontal-then-vertical order. For example, overflow: hidden auto sets horizontal overflow to hidden and vertical overflow to auto. The longhands make axis intent explicit, as in overflow-x: auto for a horizontally scrolling table.

There is an important computation rule: if one axis is neither visible nor clip, then visible on the other axis computes to auto, and clip computes to hidden. Consequently, this does not preserve visible vertical spill:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
.example {
  overflow-x: hidden;
  overflow-y: visible; /* computes to auto */
}

To pair visible overflow on one axis with clipping on the other without that particular conversion, clip can pair with visible. Check the computed styles in browser developer tools when an axis behaves differently from the authored value. The axis rules are defined in the W3C specification and explained in MDN’s reference.

Keep scrollable content accessible

A scrollable region may not be keyboard-focusable by default in some browsers. If users need to operate it with a keyboard, consider making it focusable with tabindex="0". Give a significant region an accessible name, for example with role="region" and aria-label or aria-labelledby, so screen-reader users can identify it.

Take particular care with interactive content inside clipped regions. With hidden, moving focus may cause the region to scroll to that content. With clip, a focusable element can receive keyboard focus while remaining outside the visible area, making it inaccessible to keyboard users. Do not use clip for content people need to find or operate. MDN covers these focus and scrolling considerations in its overflow guidance.

Why a page has a horizontal scrollbar

A horizontal scrollbar means some content or layout is extending the scrollable area beyond the available width. Identify the overflowing element and address its cause rather than automatically hiding the page’s horizontal overflow: hiding it can conceal content that users need.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Check whether a child has a fixed or minimum width larger than its container or viewport.
  • For long words or unbroken strings, consider overflow-wrap or word-break before adding a horizontal scroll region. MDN discusses these options in Handling overflow.
  • For wide content that should retain its width, such as a table, constrain a wrapper and use overflow-x: auto on that wrapper instead of forcing the entire page to scroll.
  • Inspect computed overflow values on both axes; a declared visible may compute to auto when paired with a non-visible, non-clip value.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Distinguish visible ink from scrollable overflow

A shadow or outline protruding beyond a box is not necessarily enlarging the scrollable area. Shadows, outlines, text decoration, border images, and overhanging glyphs are examples of ink overflow: they can paint outside the box without extending the scrollable overflow region. This distinction is set out in the MDN overflow guide.

Troubleshoot unexpected clipping or missing scrolling

  1. Check the constraint. Inspect the element’s computed width, height, and maximum sizes, then compare those with its content. If the box can grow freely, it may not overflow or scroll. See MDN’s property guidance.
  2. Identify the overflowing axis. Use overflow-x or overflow-y to express whether horizontal or vertical scrolling is intended. The specification defines the axis controls.
  3. Inspect computed styles for both axes. A paired-axis computation rule can change visible to auto or clip to hidden.
  4. Decide whether the content must stay reachable. Choose auto or scroll for user scrolling, hidden when programmatic or focus scrolling is intended, and clip only for content that can safely be cropped.
  5. For long words or tokens, try wrapping first. Use overflow-wrap or word-break when breaking the string is better than making the surrounding content horizontally scroll. See MDN’s overflow handling guide.
  6. For scrollbar-related layout shifts, consider a stable gutter. Use scrollbar-gutter: stable with overflow: auto if reserving scrollbar space is the goal.

Capture a page to inspect its rendered layout

A screenshot can help you inspect how overflow appears in a rendered page, although it does not replace checking computed styles, keyboard behavior, or scrolling interactively. For a reproducible capture, set the target URL and use the same viewport and page state when comparing changes.

Or skip the browser setup

ScreenshotNeo offers a screenshot API and MCP server for developers. One GET request can return an image or PDF; this cURL example saves a WebP screenshot of the target page. See the ScreenshotNeo documentation for the API details.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo accepts cookie and consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, with response headers indicating the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Visit ScreenshotNeo or sign up free for 1,000 screenshots a month, no card.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.