CSS Overflow

We know that every single element on a page is a rectangular box and the size, positioning and behavior of these boxes are controlled via CSS.

Let’s take an example: If you don’t set the height of the box, it will grow as large as the content. But if you set a specific height or width of the box and the content inside cannot fit then what will happen. The CSS overflow property is used to overcome this problem. It specifies whether to clip content, render scroll bars, or just display content.

CSS Overflow property values

ValueDescription
visibleIt specifies that overflow is not clipped. it renders outside the element’s box.this is a default value.
hiddenIt specifies that the overflow is clipped, and rest of the content will be invisible.
scrollIt specifies that the overflow is clipped, and a scroll bar is used to see the rest of the content.
autoIt specifies that if overflow is clipped, a scroll bar is needed to see the rest of the content.
inheritIt inherits the property from its parent element.
initialIt is used to set the property to its initial value.

CSS Overflow Example

    <!DOCTYPE html>  
    <html>  
    <head>  
    <style>  
    div.scroll {  
        background-color: #00ffff;  
        width: 100px;  
        height: 100px;  
        overflow: scroll;  
    }  
      
    div.hidden {  
        background-color: #00FF00;  
        width: 100px;  
        height: 170px;  
        overflow: hidden;  
    }  
    </style>  
    </head>  
    <body>  
    <p>The overflow property specifies what to do if the content of an element exceeds the size of the element's box.</p>  
    <p>overflow:scroll</p>  
    <div class="scroll">You can use the overflow property when you want to have better control of the layout.  
     The default value is visible.</div>  
    <p>overflow:hidden</p>  
    <div class="hidden">You can use the overflow property when you want to have better control of the layout.   
    The default value is visible.</div>  
    </body>  
    </html>  

Was this article helpful?

Related Articles

Leave A Comment?