CSS / Reference / overflow: Visible Overflow, Scrolling, Hidden, and Clip

CSS overflow decides what happens when content extends outside its box. Use auto to make the box scroll when its contents need more room. To cut off decorative overflow, choose between hidden, which still allows programmatic scrolling, and clip, which prevents scrolling.

Which overflow value should you use?

Value What happens when content overflows
visible Content can appear outside the box. This is the initial value.
auto Users can scroll through the overflowing content inside the box.
scroll The box is a scroll container. Scrollbar visibility depends on the platform and browser settings.
hidden Clips the overflow, with programmatic scrolling still available.
clip Clips the overflow and prevents scrolling, including through JavaScript.

W3C specification for the CSS overflow properties

Compare scrolling in identical boxes

Save the complete example as overflow-example.html in UTF-8 and open it in a browser. The three 72px-high boxes have identical content.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Compare scrolling in identical boxes</title>
  <style>
    body { margin: 1rem; font: 1rem/1.5 system-ui, sans-serif; }
    .box { height: 72px; max-width: 20rem; border: 1px solid #547399; }
    .content { min-height: 180px; padding: .5rem; background: #edf5ff; }
    .auto { overflow: auto; }
    .hidden { overflow: hidden; }
    .clip { overflow: clip; }
    .box:focus-visible { outline: 2px solid #104da2; outline-offset: 2px; }
  </style>
</head>
<body>
  <p id="auto-label">overflow: auto</p>
  <div class="box auto" tabindex="0" role="region" aria-labelledby="auto-label">
    <div class="content">Content for testing scrolling. This text and the pale background are inside an area taller than the visible box.</div>
  </div>
  <p>overflow: hidden</p>
  <div class="box hidden"><div class="content">Content for testing scrolling. This text and the pale background are inside an area taller than the visible box.</div></div>
  <p>overflow: clip</p>
  <div class="box clip"><div class="content">Content for testing scrolling. This text and the pale background are inside an area taller than the visible box.</div></div>
  <p>
    <button type="button" id="move">Scroll 50px</button>
    <button type="button" id="reset">Reset position</button>
  </p>
  <p id="result" role="status"></p>
  <script>
    const boxes = [...document.querySelectorAll(".box")];
    const modes = ["auto", "hidden", "clip"];
    const result = document.querySelector("#result");
    function moveTo(top) {
      boxes.forEach(box => { box.scrollTop = top; });
      result.textContent = boxes.map((box, i) =>
        modes[i] + ": " + box.scrollTop + " px"
      ).join(" / ");
    }
    document.querySelector("#move").addEventListener("click", () => moveTo(50));
    document.querySelector("#reset").addEventListener("click", () => moveTo(0));
  </script>
</body>
</html>

You can scroll the first box with a wheel or touch. Click Scroll 50px to get auto: 50 px / hidden: 50 px / clip: 0 px. Reset position brings all three offsets back to zero.

With a keyboard, press Tab to focus the first box and use the arrow keys to scroll. When building a real scroll region, give it a name that describes its contents and check that keyboard users can enter and leave it.

How hidden and clip differ

hidden creates a scroll container. Changing scrollTop or moving focus to a descendant can scroll the contents. clip leaves the contents fixed because it does not create a scroll container.

If a block needs to clip decoration and also contain floats, combine overflow: clip with display: flow-root. clip alone does not establish an independent block formatting context. Check that the clipping leaves controls and focus outlines visible.

Set horizontal and vertical overflow

With two values, the first sets overflow-x and the second sets overflow-y. For example, overflow: visible auto computes to auto on both axes.

With overflow: clip auto, the horizontal computed value varies by browser. The older rules turn it into hidden. Browsers with single-axis scrolling keep clip. Check both computed values in the browsers you support.

Chrome’s explanation of single-axis scroll containers

For vertical scrolling, check whether something like max-height constrains the box. An unconstrained block may grow to fit its content. For horizontal scrolling, the box’s used width must leave the content with less space than it needs.

Troubleshoot missing or page-wide scrolling

If a flex row widens the whole page, inspect the flex item that wraps the intended scroll box. Its content-based minimum size may keep it from shrinking. Try min-width: 0 on that item and overflow-x: auto on the inner box. In a flex column, check whether setting min-height: 0 lets the item shrink.

W3C rules for automatic minimum sizes of flex items

To wrap long URLs or strings while keeping them readable, see CSS overflow, long text wrapping, and ellipsis.