CSS overflow-y Property

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 4 Examples
Layout & Scrolling

What You’ll Learn

The overflow-y property controls what happens when content is taller than its container. It is essential for vertical scroll areas, fixed-height panels, chat lists, and modal bodies.

01

Vertical Overflow

Manage tall content.

02

Four Values

visible to auto.

03

Default visible

Show outside box.

04

Scrollbars

auto vs scroll.

05

Clip Content

Use hidden.

06

overflow-x

Horizontal axis.

Introduction

The overflow-y property in CSS controls what happens to the content when it overflows the vertical bounds of its container.

This property is particularly useful for managing vertical scrolling and ensuring that overflowing content is handled gracefully inside fixed-height layouts.

It applies only to the vertical axis, as opposed to the more general overflow property, which sets behavior for both axes at once.

Definition and Usage

Use overflow-y on elements with a defined height when content might exceed that height, such as chat message lists, modal bodies, sidebar panels, and scrollable article previews.

overflow-y: auto is the most common choice because a vertical scrollbar appears only when content actually overflows.

💡
Beginner Tip

Start with a 100px-tall container and several paragraphs plus overflow-y: auto;. Scroll vertically inside the box to see the effect.

📝 Syntax

The syntax for the overflow-y property is as follows:

syntax.css
element {
  overflow-y: value;
}

Here, value can be one of the predefined keywords described below.

Basic Example

overflow-y.css
.container {
  height: 200px;
  overflow-y: auto;
}

Syntax Rules

  • Accepted values: visible, hidden, scroll, and auto.
  • The container usually needs a set height or max-height for vertical overflow to matter.
  • overflow-y controls only the vertical axis; pair it with overflow-x for horizontal behavior.
  • auto is usually better than scroll when you want scrollbars only when needed.

🎯 Default Value

The default value of the overflow-y property is visible. This means that if the content overflows vertically, it will not be clipped and will instead be visible beyond the bounds of its container.

Change it when you want to clip tall content or add vertical scrolling inside a fixed-height box.

⚡ Quick Reference

QuestionAnswer
Initial valuevisible
Applies toBlock containers and flex/grid items
InheritedNo
AnimatableNo
Common useVertical scroll areas, chat panels, modal bodies, clipped tall content

💎 Property Values

ValueExampleDescription
visibleoverflow-y: visible;The content is not clipped, and it may overflow outside the content box.
hiddenoverflow-y: hidden;The content is clipped, and no scrollbars are provided to see the hidden content.
scrolloverflow-y: scroll;The content is clipped, but a vertical scrollbar is added to allow the user to scroll to see the rest of the content.
autooverflow-y: auto;The browser decides whether to display a vertical scrollbar. If the content fits, no scrollbar is shown; otherwise, a scrollbar appears.
visible — default hidden — clip height scroll — always scroll auto — scroll when needed

👀 Live Preview

Same tall content in short boxes with different overflow-y values (scroll inside the boxes):

auto

Tall vertical content block with extra lines that extend below the box.

Scroll inside to read more.

Only appears when needed.

hidden

Tall vertical content block with extra lines that extend below the box.

Bottom text is clipped.

No scrollbar is shown.

scroll

Tall vertical content block with extra lines that extend below the box.

Scrollbar track stays visible.

Scroll to see the rest.

Examples Gallery

Scroll tall content vertically, clip overflow, compare scrollbar behavior, and build chat-style message lists.

↕ Vertical Scroll Areas

Use overflow-y: scroll or auto when content may exceed a fixed container height.

Example 1 — Box with overflow-y: scroll

In this example, we’ll use the overflow-y property to add a vertical scrollbar to a 200px by 100px box containing lorem ipsum paragraphs.

overflow-y-scroll.html
<style>
  .overflow-box {
    width: 200px;
    height: 100px;
    border: 1px solid #000;
    overflow-y: scroll;
  }
</style>

<div class="overflow-box">
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent non nulla ut nunc fermentum dapibus.</p>
  <p>Maecenas et ligula sit amet neque consequat aliquet. Nullam varius eros at eros efficitur.</p>
</div>
Try It Yourself

How It Works

A vertical scrollbar appears because the paragraph content exceeds the 100px container height.

Example 2 — Scrollable Panel with overflow-y: auto

Use overflow-y: auto on a fixed-height panel so a vertical scrollbar appears only when content overflows.

overflow-y-auto.css
.panel {
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid #cbd5e1;
  border-radius: 0.5rem;
  padding: 1rem;
}
Try It Yourself

How It Works

The panel scrolls vertically only when release notes exceed the max-height limit.

🔄 Clip & Chat Layouts

Hide vertical overflow or build scrollable message lists inside fixed-height UI regions.

Example 3 — Clip Content with hidden

Hide vertically overflowed content without showing scrollbars.

overflow-y-hidden.css
.card {
  height: 120px;
  overflow-y: hidden;
  border: 1px solid #e2e8f0;
  border-radius: 0.5rem;
}
Try It Yourself

How It Works

Content beyond the bottom edge is cut off and cannot be scrolled into view.

Example 4 — Chat Message List

Keep a chat or message list scrollable inside a fixed-height container with overflow-y: auto.

chat-list.css
.chat-messages {
  height: 200px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 0.75rem 1rem;
}
Try It Yourself

How It Works

The message list scrolls vertically while the chat header stays fixed above it.

overflow vs overflow-x vs overflow-y

The shorthand overflow sets both axes at once. Use overflow-x and overflow-y when horizontal and vertical behavior should differ.

overflow-companion.css
.modal-body {
  overflow-y: auto;
  overflow-x: hidden;
}

♿ Accessibility

  • Do not hide important content — Using overflow-y: hidden can remove information from view with no way to scroll to it.
  • Ensure scrollable areas are usable — Keyboard users should be able to scroll focusable content inside vertical overflow containers.
  • Prefer auto over scroll — when you want vertical scrollbars only when content actually overflows.
  • Test small screens — Vertical overflow behavior affects modal dialogs, sidebars, and mobile panel layouts.

🧠 How overflow-y Works

1

Content exceeds container height

Long text, lists, images, or child elements may extend past the bottom edge.

Content
2

overflow-y value is applied

The browser decides whether to show, clip, or scroll extra height vertically.

Value
3

Layout stays controlled

Vertical scrollbars or clipping keep the page design tidy and predictable.

Result
=

Managed vertical overflow

Users can scroll up and down or see clipped content based on your choice.

Browser Compatibility

The overflow-y property is well-supported across modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. It’s essential to test your designs in different browsers to ensure consistent behavior, especially when working with complex layouts or older browsers.

Baseline · Universal support

Excellent support everywhere

visible, hidden, scroll, and auto work reliably in all major browsers.

99% Global browser support
Google Chrome 1+ · All versions
Full support
Mozilla Firefox 1+ · All versions
Full support
Apple Safari 1+ · macOS & iOS
Full support
Microsoft Edge 12+ · All versions
Full support
Opera 4+ · All versions
Full support
overflow-y property 99% supported

Bottom line: overflow-y is a dependable property for vertical overflow in modern projects.

Conclusion

The overflow-y property is a valuable tool for controlling vertical overflow behavior in web design.

By properly using this property, you can ensure that your content is presented in a user-friendly way, whether it involves hiding overflow, providing scrollbars, or other behaviors. Experiment with different values to find the best solution for your design needs.

💡 Best Practices

✅ Do

  • Use overflow-y: auto for chat lists, modals, and sidebar panels
  • Set height or max-height on overflow containers
  • Keep message lists inside a scrollable div
  • Pair with overflow-x when axes need different behavior
  • Test vertical overflow on mobile screen sizes

❌ Don’t

  • Hide important tall content with hidden without another way to access it
  • Use scroll everywhere when auto is enough
  • Expect overflow-y to work without height constraints on the box
  • Confuse overflow-y with overflow-wrap
  • Forget keyboard access inside vertically scrollable regions

Key Takeaways

Knowledge Unlocked

Five things to remember about overflow-y

Use these points when content exceeds its container height.

5
Core concepts
02

Default visible

Show outside box.

Default
📝 03

Four Values

visible to auto.

Values
🔄 04

auto Scroll

Most common use.

Use case
05

overflow-x

Horizontal axis.

Companion

❓ Frequently Asked Questions

overflow-y controls what happens when content overflows the vertical bounds of its container, such as showing a vertical scrollbar or clipping extra height.
The default value is visible, which means overflowing content is shown outside the container along the vertical axis.
overflow is a shorthand that sets both horizontal and vertical overflow. overflow-y only affects the vertical axis.
Use auto when you want a vertical scrollbar only when content actually overflows. Use scroll when you always want vertical scrollbar tracks visible.
Both clip content, but clip also disables programmatic scrolling on the vertical axis. For most layouts, hidden is enough; clip is useful when you need stricter scroll containment.

Practice in the Live Editor

Open the HTML editor and experiment with overflow-y: auto, hidden, and scroll on tall content.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful