In certain situations an element's content may overflow its box, ending up being partially or completely invisible or perhaps fully visible buy covering another box's content. Some situations when overflowing might occur include:
- a block-level box being too wide for its containing block, either by having its width set too long or due another reason;
- an elements height being too large exceeding its containing block;
- a descendant box being positioned as absolute outside its box;
- a descendant box having negative margins;
- a text or line box being unable to break or being positioned outside its boxes (i.e. by using text-indent property);
The overflow property specifies whether a box is clipped to its padding edge and whether scrolling bars are provided to access the clipped content.
The overflow property contains following information:
- value: visible, hidden, scroll, auto or inherit;
- initial: visible;
- applies to: block containers;
- inherited: no;
- percentages: N/A;
- media: visual;
- computed value: as specified.
The value visible ensures that the overflowing element is not clipped; instead it might be rendered outside the box. The opposite from the value visible is the value hidden which makes sure that the element gets clipped. This value also removes the scrolling interfaces that otherwise would have been rendered automatically if the value is set to auto or regardless if the value is set to scroll. Although the value scroll rendering depends on the browsers, the practice is to make the scrolling interface visible, even if the content is not overflowing. Such a setting might be visually unattractive but prevents the scrolling bars from appearing or disappearing when the content overflows and the value is set to auto.
CSS elements overflowing example: