CSS overflow
- type
- property
- applies to
- block containers with a set size
- inherits
- no
- common values
- visible (default), hidden, auto, scroll; overflow-x / overflow-y for one axis
Where it goes
On the box that has a fixed width or height. A box that just grows with its content never overflows, so there is nothing to decide.
Example
.log {
height: 240px;
overflow: auto;
}
.avatar {
border-radius: 50%;
overflow: hidden;
}Common mistakes
- Setting overflow: auto on a box with no height. It never overflows, so nothing scrolls. The box needs a height, a max-height, or a flex or grid parent holding it in.
- Using overflow: hidden to fix a layout problem without finding the cause. It hides the symptom. The content is still too big, and whatever got cut off is now invisible to everyone.
- Forgetting that overflow: hidden also clips absolute-positioned children that reach past the edge. A dropdown menu inside such a box gets cut off.