Lesson 13 of 50
cssOverflow & Scrollbars
6 mins
Course progress26%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 13 of 50
css6 mins
Keep these ideas in mind as you work through the lesson.
The overflow property decides what happens when a child element is larger than its container.
| Value | Behaviour |
|---|---|
visible | Default – overflow spills out, no clipping. |
hidden | Content outside the box is clipped and not visible. Useful for UI tricks like image cropping. |
auto | Scrollbars appear only when needed. |
scroll | Scrollbars are always present, even if the content fits. |
overlay (deprecated) | Scrollbars overlay the content without taking space. |
You can also control each axis independently with overflow-x / overflow-y.
.gallery {
display:flex; /* lay items side‑by‑side */
overflow-x:auto; /* horizontal scroll when needed */
gap:1rem;
padding:1rem;
scroll-snap-type:x mandatory; /* optional – snaps to each item */
}
.gallery > * { scroll-snap-align:start; }
.element {
overflow:auto;
scrollbar-width:none; /* Firefox */
-ms-overflow-style:none; /* IE 10+ */
}
.element::-webkit-scrollbar { display:none; } /* Chrome, Safari */
Perfect for image carousels where the UI provides its own arrows.