CSS overflow

Theory & Explanation

The overflow property in CSS controls what happens when content overflows the bounds of its container. It is essential for managing scrollbars, hiding excess content, and creating scrollable areas. The main values are:

When to Use overflow

Best Practices

Code Examples

/* Basic overflow */
.overflow-visible { overflow: visible; }
.overflow-hidden { overflow: hidden; }
.overflow-scroll { overflow: scroll; }
.overflow-auto { overflow: auto; }

/* Overflow X/Y */
.overflow-x-scroll { overflow-x: scroll; }
.overflow-y-auto { overflow-y: auto; }

Interactive Demos

overflow: visible (default)
This content overflows the box and is still visible outside the border. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque euismod, nisi eu consectetur.
Content spills out of the box.
overflow: hidden
This content is clipped and anything outside the box is hidden. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque euismod, nisi eu consectetur.
Overflowing content is not visible.
overflow: scroll
This content is clipped, but scrollbars are always visible. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque euismod, nisi eu consectetur.
Scrollbars are always shown, even if not needed.
overflow: auto
This content is clipped, and scrollbars appear only when needed. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque euismod, nisi eu consectetur.
Scrollbars appear only if content overflows.

Try resizing your browser or adding more content to see how each overflow value behaves.

← Back to Home