The overflow property determines whether to clip the content or introduce scrollbars when an element’s content exceeds its defined area.
It offers the following options:
Note: The overflow property exclusively applies to block elements with a specified height. Note: In OS X Lion (on Mac), scrollbars are initially concealed and only become visible when in use, despite the presence of “overflow: scroll”. |
By default, overflow is set to visible, allowing content to extend beyond the element’s box without being clipped.
Example
div { width: 200px; height: 65px; background-color: coral; overflow: visible; } |
When set to “hidden”, overflow is clipped, resulting in the concealment of any excess content.
Example
div { overflow: hidden; } |
When the value is set to “scroll”, overflow is clipped, and scrollbars are introduced to navigate through the content within the box. It’s important to note that this may generate both horizontal and vertical scrollbars, even if not both are required.
Example
div { overflow: scroll; } |
The “auto” value functions similarly to “scroll”, but it introduces scrollbars solely when needed.
Example
div { overflow: auto; } |
The overflow-x and overflow-y properties determine whether to adjust the overflow of content horizontally, vertically, or in both directions.
overflow-x dictates the handling of content overflow along the left and right edges. overflow-y dictates the handling of content overflow along the top and bottom edges.
Example
div { overflow-x: hidden; /* Hide horizontal scrollbar */ overflow-y: scroll; /* Add vertical scrollbar */ } |
Property |
Description |
overflow |
Specifies the behavior when content exceeds the boundaries of an element’s box. |
overflow-wrap |
Specifies whether the browser is allowed to break lines containing long words that overflow their container. |
overflow-x |
Specifies the handling of content overflow along the left and right edges of the element’s content area. |
overflow-y |
Specifies the handling of content overflow along the top and bottom edges of the element’s content area. |