In CSS, the overflow
property is used to control the behavior of content that overflows its containing element. It is often used in conjunction with a specified height or width to define how the content should behave when it exceeds the specified dimensions. The overflow
property can take several values:
visible (default): Content is not clipped, and it may overflow the content box.
css.example { overflow: visible; }
hidden: Content that overflows is clipped and not visible.
css.example { overflow: hidden; }
scroll: Adds a scrollbar to the element, allowing the user to scroll and see the hidden content.
css.example { overflow: scroll; }
auto: Similar to scroll, but a scrollbar is only added if the content overflows.
css.example { overflow: auto; }
inherit: The overflow
property inherits its value from the parent element.
css.example { overflow: inherit; }
Here's a simple example illustrating the use of the overflow
property:
css.container { width: 200px; height: 100px; overflow: scroll; } .content { width: 300px; height: 150px; background-color: lightblue; }
html<div class="container">
<div class="content">
<!-- Content that exceeds the container dimensions -->
<!-- Scrollbars will appear due to the overflow: scroll; property -->
</div>
</div>
In this example, the content within the .content
div exceeds the dimensions specified by the .container
div, and the scrollbars will appear because of the overflow: scroll;
property on the container.
Adjust the values and properties based on your specific layout and design requirements.