Controlling Content Flow: The CSS Overflow Property

Master the CSS `overflow` property. Learn to clip, scroll, and manage content that's too big for its container using hidden, scroll, auto, and more.

Lesson ProgressStep 1 of 10

This is a lot of content. In fact, it's so much content that it probably won't fit inside its container. When content is bigger than its box, we call it overflow. Let's see how to manage this overflow.

0 EXP

Let's see what happens when content is too big for its container. This is called 'overflow'.

.box {
  width: 200px;
  height: 100px;
  border: 2px solid blue;
  /* overflow: visible; (default) */
}

What is Overflow?

Overflow is what happens when the content inside a box is too big to fit. This can happen if you set a fixed `height` or `width` on an element, and the text, images, or child elements inside it are larger than those dimensions.

By default, the `overflow` property is set to `visible`, which means the content will just spill out of the box, often overlapping other elements and breaking your page layout.

.box {
  width: 100px;
  height: 100px;
  overflow: visible; /* This is the default */
}

System Check

What is the default value of the `overflow` property?

Advanced Holo-Simulations

0 EXP

Log in to unlock these advanced training modules and test your skills.


Achievements

🏆
Overflow Master

Use hidden, scroll, and auto properties in an exercise.

🏗️
Scroll Manager

Correctly differentiate between `scroll` and `auto` values.

✍️
Axis Controller

Prove your mastery of `overflow-x` and `overflow-y`.

Mission: Tame the Overflow

The box below has too much content. Use CSS to manage it. Try to add `overflow: hidden`, `overflow-y: scroll`, and `overflow-x: auto` to see what they do. Our AI assistant will provide real-time feedback.

A.D.A. Feedback:

> System integrity looks stable. Properties are applied.

Challenge: Order the Values

Drag the properties into the correct logical order: 1. `hidden`, 2. `scroll`, 3. `auto`.

overflow: scroll;
overflow: hidden;
overflow: auto;

Challenge: Complete the Syntax

Fill in the missing properties to hide horizontal overflow but allow vertical scrolling.

.chat-widget {
:;
: auto;
}

Consult A.D.A.

Community Holo-Net

Peer Project Review

Submit your "Tame the Overflow" project for feedback from other Net-Runners.

Beyond the Box: A Deep Dive into CSS Overflow

In a perfect world, all our content would fit neatly inside the boxes we design. But on the web, we deal with dynamic content, user-generated text, and wildly different screen sizes. Sooner or later, you'll face **overflow**: content that is too big for the container you've assigned it. CSS gives us the `overflow` property, a powerful tool to manage this inevitability.

The Four Core Overflow Values

The `overflow` property is a shorthand that controls overflow on both the X (horizontal) and Y (vertical) axes. It primarily takes one of four values:

  • visible: This is the **default**. Content is not clipped and simply renders outside its container's box. This can break your layout by pushing other elements around or overlapping them.
  • hidden: This value **clips** the content. Anything that overflows is simply cut off and becomes invisible. It's a hard cut—the user gets no scrollbars and cannot access the hidden content. This is useful for certain visual effects but poses a major accessibility risk.
  • scroll: This value also clips the content, but it **always displays scrollbars** for both the X and Y axes, allowing the user to scroll to see the rest of the content. Scrollbars will appear even if the content fits perfectly, which can sometimes be visually undesirable.
  • auto: This is the "smart" value and often the best choice. It behaves like `visible` if the content fits, but if the content overflows, it behaves like `scroll`, adding scrollbars **only on the axis (or axes) where they are needed**.

Controlling the Axes: `overflow-x` and `overflow-y`

The real power of `overflow` comes when you control the axes independently. You'll rarely want to manage horizontal and vertical overflow in the same way.

✔️ Good Practice: Horizontal Scroll

Use case: A wide table or code block on a mobile screen that you don't want to squish.

.table-wrapper {
  overflow-x: auto;
  overflow-y: hidden;
}

✔️ Good Practice: Vertical Scroll

Use case: A chat box, a modal body, or a navigation list that needs a fixed height.

.chat-box {
  height: 300px;
  overflow-y: auto;
  overflow-x: hidden;
}

By setting `overflow-x: hidden` and `overflow-y: auto`, you are making a clear statement: "My content should never break out horizontally, but if it gets too tall, please provide a vertical scrollbar." This is a very common and robust pattern.

The New Contender: `overflow: clip`

Modern CSS has introduced `overflow: clip`. It's very similar to `overflow: hidden`—it clips the content at the container's edge. The key difference is that `clip` **does not allow the user to scroll at all**, not even programmatically. It's a "harder" clip.

Why use it? Performance. Because the browser knows that scrolling is impossible, it can make optimizations that it can't make for `overflow: hidden` (which *technically* still establishes a scroll container). For simple visual clipping, `clip` is often a better, more performant choice.

Accessibility Warning: Never use `overflow: hidden` or `overflow: clip` to hide content that is essential to the user. If a keyboard user tabs to an element that is inside a hidden overflow, they can't see what they are focusing on. Use these properties for decorative elements or when you are 100% sure the hidden content is non-essential.

Mastering `overflow` is about more than just preventing "broken" layouts. It's about gracefully handling the unpredictable nature of web content, ensuring your site is usable and accessible whether it's displaying a single word or an entire novel.

CSS Overflow Glossary

overflow
A shorthand CSS property that sets how an element's content is handled when it overflows its block-level container on both the X (horizontal) and Y (vertical) axes.
overflow-x
A CSS property that controls how content overflows its container specifically along the horizontal (X) axis.
overflow-y
A CSS property that controls how content overflows its container specifically along the vertical (Y) axis.
visible
The default value for overflow. Content is not clipped and may be rendered outside the element's container, potentially overlapping other elements on the page.
hidden
Content is clipped at the container's edge (its padding-box). Any overflowing content is made invisible, and no scrollbars are provided to access it. This also creates a new Block Formatting Context (BFC).
scroll
Content is clipped, but the browser always displays scrollbars (both horizontal and vertical), whether the content is overflowing or not. This can be used to prevent layout shifts.
auto
The "smart" value. The browser adds scrollbars only on the axes where the content is actually overflowing. If content fits, it appears as visible. If it overflows, it behaves like scroll. This is the most common value for scrollable areas.
clip
A modern value similar to hidden. Content is clipped at the container's edge. It is more performant than hidden because it forbids all scrolling, including programmatic scrolling, and does not create a new BFC.
Overflowing Content
Any content (text, images, etc.) that cannot fit within its parent container's defined dimensions (its padding-box). This is the "problem" that the overflow property is designed to solve.
Clipping
The act of cutting off content at the boundary of an element. This is what happens when overflow is set to hidden, scroll, auto, or clip.
Block Formatting Context (BFC)
An important side-effect of setting overflow to any value other than visible or clip. Creating a new BFC can be used to clear floats or prevent parent-child margin collapse.
overflow-clip-margin
A CSS property that works with overflow: clip. It defines how far *outside* the element's box the content can be before it is clipped, allowing for effects like box-shadows to "escape" the clip.
text-overflow
A related property that specifies how to signal overflowing *text* content that is not displayed. It is often used with overflow: hidden and white-space: nowrap to add an ellipsis (...) to truncated text.
scrollbar-gutter
A CSS property that provides control over the space reserved for a scrollbar, preventing layout shifts that can occur when overflow: auto adds or removes a scrollbar as content changes.

About the Author

Author's Avatar

TodoTutorial Team

Passionate developers and educators making programming accessible to everyone.

This article was written and reviewed by our team of web development experts, who have years of experience teaching CSS and building robust and accessible web applications.

Verification and Updates

Last reviewed: October 2025.

We strive to keep our content accurate and up-to-date. This tutorial is based on the latest CSS specifications and is periodically reviewed to reflect industry best practices.

External Resources

Found an error or have a suggestion? Contact us!