CSS Layout - Overflow

The CSS overflow property controls what happens to content that is too big to fit into an area.


CSS Overflow

The overflow property specifies whether to clip the content or to add scrollbars when the content of an element is too big to fit in the specified area.

  • visible - Default. The overflow is not clipped. The content renders outside the element's box.
  • hidden - The overflow is clipped, and the rest of the content will be invisible.
  • scroll - The overflow is clipped, and a scrollbar is added to see the rest of the content.
  • auto - Similar to scroll, but it adds scrollbars only when necessary.

overflow: visible

By default, the overflow is visible, meaning that it is not clipped and content renders outside the element's box:

Output :

overflow: hidden

With the hidden value, the overflow is clipped, and the rest of the content is hidden:

Output :

overflow: scroll

Setting the value to scroll, the overflow is clipped and a scrollbar is added to scroll inside the box. Note that this will add a scrollbar both horizontally and vertically (even if you do not need it):

Output 3:

overflow: auto

The auto value is similar to scroll, but it adds scrollbars only when necessary:

Output :

overflow-x and overflow-y

The overflow-x and overflow-y properties specify whether to control the overflow of content horizontally or vertically.

overflow-x handles overflow on the left/right (horizontal) edges of the content.

overflow-y handles overflow on the top/bottom (vertical) edges of the content.

Output:-: