visible, the default, lets overflowing content spill outside its container's boundaries with no clipping at all; hidden clips any overflowing content, making it completely invisible with no way to access it; scroll always displays scrollbars, even when content actually fits without needing to scroll; and auto only shows scrollbars when the content genuinely overflows, remaining scrollbar-free otherwise, generally the more polished default choice over scroll. overflow-x and overflow-y let each axis be controlled independently, useful for a container that should scroll vertically but never horizontally, for instance.
1Understanding Overflow
visible, the default, lets overflowing content spill outside its container's boundaries with no clipping at all; hidden clips any overflowing content, making it completely invisible with no way to access it; scroll always displays scrollbars, even when content actually fits without needing to scroll; and auto only shows scrollbars when the content genuinely overflows, remaining scrollbar-free otherwise, generally the more polished default choice over scroll. overflow-x and overflow-y let each axis be controlled independently, useful for a container that should scroll vertically but never horizontally, for instance.
Prefer overflow: auto over overflow: scroll in most cases — auto only shows scrollbars when content genuinely overflows, while scroll always displays them even when unnecessary, which can look visually cluttered for content that happens to fit already.
.card {
height: 200px;
overflow-y: auto;
}2Practical Example
Here is a real-world application of Overflow showing how it is used in production CSS code.
.truncated {
height: 100px;
overflow: hidden;
}3Best Practices
Follow these guidelines when working with Overflow:
1. Use overflow: auto rather than scroll for the more polished default of only showing scrollbars when content genuinely needs to scroll
2. Use overflow: hidden deliberately to intentionally clip content, and be aware it's also commonly used as an unrelated technique to contain floated children or establish a new block formatting context
3. Set overflow-x and overflow-y independently when only one axis, not both, should scroll or clip
Tip: Prefer overflow: auto over overflow: scroll in most cases — auto only shows scrollbars when content genuinely overflows, while scroll always displays them even when unnecessary, which can look visually cluttered for content that happens to fit already.
.card {
height: 200px;
overflow-y: auto;
}