CSS Overflow

The CSS overflow property controls what happens when content overflows an element's box. By default, content that overflows an element is displayed outside the box, but this behavior can be changed using the overflow property. This property is especially useful when working with fixed dimensions and dynamic content.

Key Points on CSS Overflow:

Syntax for CSS Overflow:

Syntax Example

/* Syntax for overflow */
        overflow: visible | hidden | scroll | auto;
                
        /* Example */
        overflow: hidden;

Examples of CSS Overflow:

The following examples demonstrate the usage of the overflow property:

Code Example: Overflow Hidden

div {
            overflow: hidden;
            width: 200px;
            height: 100px;
            border: 1px solid black;
        }

Output

Content that overflows will be hidden in this container.

Code Example: Overflow Scroll

div {
            overflow: scroll;
            width: 200px;
            height: 100px;
            border: 1px solid black;
        }

Output

Content that overflows will trigger scrollbars in this container.

Code Example: Overflow Auto

div {
            overflow: auto;
            width: 200px;
            height: 100px;
            border: 1px solid black;
        }

Output

Scrollbars appear only if the content overflows in this container.

Common Overflow Values:

Overflow properties are particularly useful in scenarios where you want to manage content within a fixed-size container, such as navigation menus, image galleries, or content sliders. Proper use of these properties can improve usability and prevent content from spilling out of view.