Understanding overflow: visible, hidden, scroll, and auto
You'll learn how to control what happens when content is too big for its container.
What Is Overflow?
When you set specific dimensions on an element (using width and height), sometimes the content inside doesn't fit. The overflow property tells the browser what to do in this situation.
Think of it like packing a suitcase: if your clothes don't fit, you can let them spill out (visible), cram the lid shut and hide what doesn't fit (hidden), or add rolling compartments to access everything (scroll/auto).
The Four Values
overflow: visible (default)
Content that doesn't fit simply overflows outside the container's boundaries. The content is still visible and can overlap other elements.
overflow: hidden
Any content that exceeds the container's dimensions is clipped and completely hidden from view. It's still in the document, but users can't see or access it.
overflow: scroll
The browser adds scrollbars (both horizontal and vertical) to the container, allowing users to scroll to see all the content. Scrollbars appear even if the content fits.
overflow: auto
The browser intelligently adds scrollbars only when needed. If content fits, no scrollbars appear. If content overflows, scrollbars appear automatically.
Why This Matters
You control whether content breaks your layout (visible), gets cut off (hidden), or becomes accessible through scrolling (scroll/auto). Most modern designs use overflow: auto for flexibility, while overflow: hidden is useful for intentionally cropping content or preventing scroll on the body element.
Key Takeaway: The overflow property controls content visibility when it exceeds container boundaries: visible lets it spill, hidden clips it, scroll always adds scrollbars, and auto adds scrollbars only when needed.