CSS Overflow
CSS overflow
is a property that controls how content overflows its container when it exceeds the available space. It is used to specify how the browser should handle the content that cannot fit within the specified dimensions of an element.
The overflow
property can take several values:
visible
(default): Content is not clipped and may extend beyond the container’s boundaries.hidden
: Content is clipped and anything that exceeds the dimensions of the container is hidden.scroll
: Content is clipped, and a scrollbar is added to the container, allowing users to scroll and see the hidden content.auto
: Similar toscroll
, a scrollbar is added only if necessary. If the content fits within the container, no scrollbar is added.overlay
: Content is clipped and a scrollbar is added only if necessary, but the scrollbar is overlaid on top of the content, instead of occupying space within the container.
Here’s an example of how you can use the overflow
property:
css
.container {
width: 300px;
height: 200px;
overflow: scroll;
}
In the example above, the container element has a fixed width and height of 300px and 200px, respectively. If the content inside the container exceeds these dimensions, a scrollbar will appear, allowing the user to scroll and see the hidden content.
By adjusting the overflow
property, you can control how the content behaves when it exceeds the container’s boundaries, giving you options to hide, scroll, or overlay the overflowed content.