The overflow property decides what happens when content is bigger than its container. It is essential for scroll areas, clipped layouts, and clean UI design.
01
Overflow Control
Manage extra content.
02
Four Values
visible to auto.
03
Default visible
Show outside box.
04
Scrollbars
scroll vs auto.
05
Clip Content
Use hidden.
06
overflow-x/y
Axis control.
Fundamentals
Introduction
The overflow property in CSS controls how content that overflows the bounds of its container is handled.
This property is crucial for managing content that exceeds the dimensions of its container, allowing you to specify how to handle overflowed content in a way that fits your design needs.
Definition and Usage
Use overflow on elements with a defined width or height when content might exceed those limits, such as cards, sidebars, code blocks, and modal bodies.
auto is the most common choice for scrollable panels because scrollbars appear only when needed.
💡
Beginner Tip
Start with a fixed-size box and overflow: auto;. If content is too long, scrollbars appear automatically.
Foundation
📝 Syntax
The syntax for the overflow property is as follows:
syntax.css
element{overflow:value;}
Here, value can be one of the defined keywords or a combination of values for each axis.
The container usually needs a set width, height, or max-size for overflow to matter.
overflow-x and overflow-y control horizontal and vertical overflow separately.
auto is usually better than scroll when you want scrollbars only when needed.
Defaults
🎯 Default Value
The default value of the overflow property is visible, meaning that content overflowing the bounds of the container will be rendered outside the container.
Change it when you want to clip content or add scrolling inside a fixed-size box.
Cheat Sheet
⚡ Quick Reference
Question
Answer
Initial value
visible
Applies to
Block containers and flex/grid items
Inherited
No
Animatable
No
Common use
Scrollable panels, clipped content, layout control
Reference
💎 Property Values
Value
Example
Description
visible
overflow: visible;
Overflowed content is visible outside the container (default)
hidden
overflow: hidden;
Overflowed content is clipped and no scrollbars are shown
Same long text in small boxes with different overflow values (scroll inside the boxes):
auto Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus lacinia odio vitae vestibulum.
hidden Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus lacinia odio vitae vestibulum.
scroll Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus lacinia odio vitae vestibulum.
Hands-On
Examples Gallery
Manage overflowing text with auto scrollbars, hidden clipping, and value comparisons.
🗃 Scrollable Containers
Use overflow: auto when content may exceed a fixed box size.
Example 1 — Container with overflow: auto
In this example, we use the overflow property to manage overflowed content within a div element.
overflow-auto.html
<style>.container{width:200px;height:100px;border:1px solid #000;overflow:auto;}</style><divclass="container"><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit...</p></div>
visible lets content extend beyond the box; hidden keeps it inside visually.
Companion
overflow-x and overflow-y
The shorthand overflow sets both axes. Use overflow-x and overflow-y when you want horizontal and vertical behavior to differ.
overflow-axes.css
.code-block{overflow-x:auto;overflow-y:hidden;}
A11y
♿ Accessibility
Do not hide important content — Using 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 overflow containers.
Prefer auto over scroll — when you want scrollbars only when content actually overflows.
Test small screens — Overflow behavior affects mobile layouts and readability.
🧠 How overflow Works
1
Content fills a container
Text, images, or child elements may exceed the box size.
Content
2
overflow value is applied
The browser decides whether to show, clip, or scroll extra content.
Value
3
Layout stays controlled
Scrollbars or clipping keep the page design tidy and predictable.
Result
=
🗃
Managed overflow behavior
Users can view, scroll, or ignore extra content based on your choice.
Compatibility
Browser Compatibility
The overflow property is well supported across all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. This makes it a reliable option for managing content overflow in various web environments.
✓ Baseline · Universal support
Excellent support everywhere
visible, hidden, scroll, and auto work reliably in all major browsers.
99%Global browser support
Google Chrome1+ · All versions
Full support
Mozilla Firefox1+ · All versions
Full support
Apple Safari1+ · macOS & iOS
Full support
Microsoft Edge12+ · All versions
Full support
Opera4+ · All versions
Full support
overflow property99% supported
Bottom line:overflow is one of the most dependable layout properties in CSS.
Wrap Up
Conclusion
The overflow property is an essential tool for managing how content that exceeds the bounds of its container is handled.
By choosing the appropriate value—whether it’s visible, hidden, scroll, or auto—you can control how users interact with overflowing content and maintain a clean and functional design for your web pages. Experiment with different values to find the best fit for your layout and design requirements.