iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

CSS Overflow

The overflow property decides what happens when content is bigger than its box. Clip it, hide it, scroll it, or just let it spill.

Values

ValueBehaviourUse it for
visibleContent spills outside the box (default).Tooltips, dropdowns that need to escape their parent.
hiddenOverflow is clipped. No scrollbar.Card thumbnails, decorative crops.
scrollScrollbars always shown, even when not needed.Avoids layout shift when content grows.
autoScrollbars only when needed.The default choice for scrollable panes.
clipLike hidden but no scrollbox is created — children with sticky positioning still work.Modern crop with sticky kids.

Per-axis control

CSS
.code-block { overflow-x: auto; overflow-y: hidden; }   /* horizontal scroll only */
.table-wrap { overflow-x: auto; }                       /* mobile-friendly wide table */
Note: Setting any value other than visible creates a new block formatting context. That's the modern way to contain floats — overflow: hidden stops floated children from poking out.

Example

Example
<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: Verdana, sans-serif; }
.box { background: #04AA6D; color: #fff; padding: 20px; border-radius: 6px; }
</style>
</head>
<body>

<h1>CSS Overflow</h1>
<div class="box">Edit the CSS on the left, then click Run &raquo;</div>

</body>
</html>
Try it Yourself »

Exercise

Show a horizontal scrollbar only when this code block is too wide.

.code { overflow-x: ; }

Test yourself

Q1. Which value shows scrollbars only when content overflows?
Q2. Which value clips content with no scrollbar?
Q3. Setting overflow to anything other than `visible`…

Discussion

Loading…