What does the CSS rule “clear: both” do?

The clear property is used to specify that which side of floating elements are not allowed to float. It sets or returns the position of the element in relation to floating the objects.

The “clear: both” means floating the elements are not allowed to float on both sides. It is used when no need of any element float on the left and right side as related to the specified element and wanted the next element only shown below. It also indicates that no other element takes up space on the left and right side.

Syntax:



clear:both; 

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html
    <head
        <style
            div { 
                width:100px; 
                height:100px; 
                background-color:green; 
                color:white; 
                font-weight:bold; 
                font-size:25px; 
                text-align:center; 
                float: left; 
                padding:15px; 
            
            p.GFG { 
                clear: both; 
            
            h1 { 
                color:green; 
                text-align:center; 
            
        </style
    </head
    <body
        <h1>GeeksForGeeks</h1
        <h1>clear:both;</h1
        <div><pre>GFG</pre></div
        <p>GeeksforGeeks: A computer science portal for geeks</p
        <p class="GFG">GeeksforGeeks</P
    </body
</html>                     

chevron_right


Output:

Supported Browsers: The supported browsers are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.