CSS Overflow


The CSS property called overflow manages what occurs when something is too large to fit in a particular space.

This text is really long and the height of its container is only 100 pixels. Therefore, a scrollbar is added to help the reader to scroll the content. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem.

CSS Overflow

The overflow property decides what to do when there's too much content for a specific space. It can either cut off the extra content or display scrollbars to let you see the hidden part.

The overflow property can take on these values.

  • "visible - This is the default setting. It means that when there's too much content to fit inside an element, it won't be cut off.
  • hidden - This hides the extra content that doesn't fit within the specified width and height.
  • scroll - When there's too much stuff on a webpage, the extra stuff gets hidden, and a little slidey bar appears so you can look at the hidden stuff.
  • auto - Like scroll, but it only shows scrollbars when they are needed.

overflow: visible

By default, overflow is set to visible which means that content is not hidden and can extend beyond the boundaries of the element's box:

In HTML, the 'overflow' property helps you control how content appears within an element. It decides what occurs when the content inside an element exceeds the element's dimensions.


Example

div {
  width: 200px;
  height: 65px;
  background-color: coral;
  overflow: visible;
}
Try it Yourself »

overflow: hidden

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

Example

div {
  overflow: hidden;
}
Try it Yourself »

overflow: scroll

When you set the value to scroll, it means that if the content inside a box is too much to fit, the extra content will be hidden, and scrollbars will appear so you can scroll both horizontally and vertically to see the hidden content.

You can use the "overflow" property to control how content behaves within an element's box. This property defines what should occur when the content exceeds the designated space.

Example

div {
  overflow: scroll;
}
Try it Yourself »

overflow: auto

The 'auto' setting is like The auto but it only shows scrollbars when they are needed:

You can use the "overflow" property to control how things are displayed. It tells us what to do if the stuff inside a box is too much to fit in that box.

Example

div {
  overflow: auto;
}
Try it Yourself »

overflow-x and overflow-y

The overflow-x and overflow-y properties decide whether to control the overflow of content in two ways: horizontally or vertically, or both.

overflow-x tells us how to handle the content's left and right edges.
overflow-y tells us how to handle the content's top and bottom edges.

You can use the "overflow" property to control how things appear on a webpage. This property tells the webpage what to do if the content doesn't fit inside a certain area.

Example

div {
  overflow-x: hidden; /* Hide horizontal scrollbar */
  overflow-y: scroll; /* Add vertical scrollbar */
}
Try it Yourself »