Overflow

Learn how to control content that is too large to fit inside an element's designated space.

What is the Overflow Property?

The CSS `overflow` property controls what happens when content is too big to fit into an element's content area. This is a common situation, especially with text that needs to fit into a fixed-size container. The `overflow` property, along with its related properties `overflow-x` and `overflow-y`, provides several ways to manage this.

Managing overflow is key to maintaining clean layouts and ensuring a good user experience, as it prevents content from unexpectedly spilling out and disrupting other elements on the page.

Overflow Property Values

There are four main values for the `overflow` property:

visible (Default)

The overflowing content is not clipped and is rendered outside the element's box. It's as if the overflow property isn't even set.

hidden

The overflowing content is clipped and the rest of the content is hidden. No scrollbars are provided to view the hidden content.

scroll

The overflowing content is clipped, but scrollbars are added to the element so that the user can scroll to see the rest of the content. Scrollbars are always visible, even if the content does not overflow.

auto

The overflowing content is clipped, but scrollbars are added only when necessary. This is the most common and user-friendly option for scrollable content.

Live Example

The following containers all have a fixed size, but they use different `overflow` property values to handle the overflowing text.

Overflow in Action

overflow: visible;

This is a long text that will overflow the container. With `overflow: visible;`, the text simply spills out of the container's bounds. This is the default behavior for most elements. This text continues to overflow...

overflow: hidden;

This is a long text that will overflow the container. With `overflow: hidden;`, the text is clipped and the rest is not visible to the user. There are no scrollbars. This text continues to overflow...

overflow: scroll;

This is a long text that will overflow the container. With `overflow: scroll;`, scrollbars are always present, even if there is no content to scroll. This text continues to overflow... and overflow... and overflow... and overflow... and overflow...

overflow: auto;

This is a long text that will overflow the container. With `overflow: auto;`, scrollbars appear only when the content is too large. This is the most practical choice. This text continues to overflow... and overflow... and overflow... and overflow... and overflow...