Overflow and scroll containers
Definition and purpose
Overflow controls what happens when content extends beyond a box. Some values create a scroll container; others simply allow or clip painting.
Scrollable log
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> #a { width: 140px; height: 50px; overflow: auto; } #a p { height: 100px; margin: 0; } </style> </head> <body> <div id="a" tabindex="0" role="region" aria-label="Log"> <p>Log entries</p> </div> </body></html>The log has more content than its visible height and can scroll.
Syntax and mental model
visible normally allows overflow. auto allows scrolling when needed; scroll creates a scroll container even without overflow. hidden clips and allows programmatic scrolling; clip prohibits scrolling. These examples set both axes via the shorthand. Mixed axis values have additional computed-value rules.
Hidden versus clip
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> div { width: 100px; height: 40px; } #a { overflow: hidden; } #b { overflow: clip; } p { height: 120px; margin: 0; } </style> </head> <body> <div id="a"> <p>Long content</p> </div> <div id="b"> <p>Decorative content</p> </div> </body></html>Both clip the long content, but only hidden supports programmatic scrolling.
Common mistakes
Do not hide overflowing text just to make a layout look tidy. Provide an accessible way to reach important content and verify keyboard access to scroll regions.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Margin collapse and negative margins. Next lesson: Aspect ratio and replaced elements.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Overflow and scroll containers — knowledge check
Five questions on overflow and scroll containers.
Which value prohibits scrolling entirely?
Which clips but still allows programmatic scrolling?
Which is suitable for a log that needs scrolling only when necessary?
What is a risk of hiding overflow on text?
Which value creates a scroll container regardless of overflow?