The Wayback Machine - https://web.archive.org/web/20241125103251/https://www.geeksforgeeks.org/css-clear-property/
Open In App

CSS clear Property

Last Updated : 26 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The clear property is used to specify which side of floating elements are not allowed to float. It sets or returns the position of the element in relation to floating objects. If the element can fit horizontally in the space next to another element that is floated, it will. 

Syntax:

clear: none|left|right|both|inline-start|inline-end|initial;

Property values:

  • none: It has a default value. It allows elements are float on both sides. 
  • left: This property specifies that elements are not allowed to Float on the left side in relation to other elements. 
  • both: It means floating elements are not allowed to float on both sides. 
  • right: It means elements are not allowed to float on the right side. 
  • initial: It sets the property to its default value.

Example: In this example, we are using clear: none property.

html
<!DOCTYPE html>
<html>
    <head>
        <style>
            div {
                width: 100px;
                height: 100px;
                background-color: green;
                color: white;
                font-weight: bold;
                font-style: itallic;
                font-size: 25px;
                text-align: center;
                float: left;
                padding: 15px;
            }

            p.GFG {
                clear: none;
            }

            h1,
            h2 {
                color: green;
                text-align: center;
            }
        </style>
    </head>

    <body>
        <h1>GeeksForGeeks</h1>
        <h1>clear:none;</h1>
        <div>
            <pre>GFG</pre>
        </div>
        <p>
            GeeksforGeeks: A computer science
            portal for geeks
        </p>
        <p class="GFG">GeeksforGeeks</p>
    </body>
</html>

Output: 

CSS clear Property example output

Example: In this example, we are using clear: left property.

html
<!DOCTYPE html>
<html>
    <head>
        <style>
            div {
                width: 100px;
                height: 100px;
                background-color: green;
                color: white;
                font-weight: bold;
                font-style: itallic;
                font-size: 25px;
                text-align: center;
                float: left;
                padding: 15px;
            }

            p.GFG {
                clear: left;
            }

            h1,
            h2 {
                color: green;
                text-align: center;
            }
        </style>
    </head>

    <body>
        <h1>GeeksForGeeks</h1>
        <h1>clear:left;</h1>
        <div>
            <pre>GFG</pre>
        </div>
        <p>
            GeeksforGeeks: A computer science
            portal for geeks
        </p>
        <p class="GFG">GeeksforGeeks</p>
    </body>
</html>

Output:

CSS clear Property example output

Example: In this example, we are using clear: right property.

html
<!DOCTYPE html>
<html>
    <head>
        <style>
            div {
                width: 100px;
                height: 100px;
                background-color: green;
                color: white;
                font-weight: bold;
                font-style: itallic;
                font-size: 25px;
                text-align: center;
                float: left;
                padding: 15px;
            }

            p.GFG {
                clear: right;
            }

            h1,
            h2 {
                color: green;
                text-align: center;
            }
        </style>
    </head>

    <body>
        <h1>GeeksForGeeks</h1>
        <h1>clear:right;</h1>
        <div>
            <pre>GFG</pre>
        </div>
        <p>
            GeeksforGeeks: A computer science
            portal for geeks
        </p>
        <p class="GFG">GeeksforGeeks</p>
    </body>
</html>

Output:

CSS clear Property example output

Example: In this example, we are using clear: both property.

html
<!DOCTYPE html>
<html>
    <head>
        <style>
            div {
                width: 100px;
                height: 100px;
                background-color: green;
                color: white;
                font-weight: bold;
                font-style: itallic;
                font-size: 25px;
                text-align: center;
                float: left;
                padding: 15px;
            }

            p.GFG {
                clear: both;
            }

            h1,
            h2 {
                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>

Output:

CSS clear Property Example output

Example: In this example, we are using clear: initial property.

html
<!DOCTYPE html>
<html>
    <head>
        <style>
            div {
                width: 100px;
                height: 100px;
                background-color: green;
                color: white;
                font-weight: bold;
                font-style: itallic;
                font-size: 25px;
                text-align: center;
                float: left;
                padding: 15px;
            }

            p.GFG {
                clear: initial;
            }

            h1,
            h2 {
                color: green;
                text-align: center;
            }
        </style>
    </head>

    <body>
        <h1>GeeksForGeeks</h1>
        <h1>clear:initial;</h1>
        <div>
            <pre>GFG</pre>
        </div>
        <p>
            GeeksforGeeks: A computer science
            portal for geeks
        </p>
        <p class="GFG">GeeksforGeeks</p>
    </body>
</html>

Output:

CSS clear Property example output

Supported Browsers: The browsers supported by clear property are listed below:

CSS clear Property – FAQs

What does the clear property do in CSS?

The clear property in CSS is used to control the behavior of floating elements. It specifies whether an element should be moved below (cleared) floating elements that precede it.

What are the possible values for the clear property?

The clear property accepts values like left, right, both, and none. Left clears elements floating to the left, right clears elements floating to the right, both clears both sides, and none does not clear any float.

How is the clear property commonly used in layouts?

The clear property is often used to prevent floating elements from overlapping with content below them, especially in multi-column layouts or floated navigation bars.

What happens if I use clear: both?

Using clear: both forces the element to be positioned below all floating elements, regardless of whether they are floated to the left or right. This is commonly used to fix layout issues.

Can clear be used with inline elements?

The clear property is primarily intended for block-level elements. It may have no visible effect on inline elements unless they are within a block context.



Previous Article
Next Article

Similar Reads

HTML | DOM Style clear Property
The DOM Style clear property in HTML is used to set or get the position of the specific element relative to floating objects. Syntax To get clear property:object.style.clearTo set clear property:object.style.clear = "none|left|right|both|initial|inherit" Properties Value: valuedescriptionleftDoes not allow floating entities on the left of the eleme
2 min read
Foundation CSS Button Clear Style
Foundation CSS is an open-source & responsive front-end framework built by ZURB foundation in September 2011, that makes it easy to design beautiful responsive websites, apps, and emails that look amazing & can be accessible to any device. It is used by many companies such as Facebook, eBay, Mozilla, Adobe, and even Disney. The framework is
3 min read
Foundation CSS Button Group Hollow and Clear
Foundation CSS is the frontend framework of CSS that is used to build responsive websites, apps, and emails that work perfectly on any device. It is written using HTML, CSS, and Javascript and is used by many famous companies like Amazon, Facebook, eBay, etc. It uses packages like Grunt and Libsass for fast coding and controlling and Saas compiler
3 min read
CSS Layout - float and clear
CSS layout is a fundamental design of web development that controls how elements are arranged and presented on a webpage. The properties of float and clear are important when it comes to layout design techniques. The "float" property positions an element to the left or right within its container, while the "clear" property prevents elements from wr
2 min read
Tailwind CSS Clear
This class accepts more than one value in Tailwind CSS. All the properties are covered in a class form. It is an alternative to the CSS clear property. This class is used to specify which side of floating elements are not allowed to float. It sets or returns the position of the element in relation to floating objects. If the element can fit horizon
5 min read
What does the CSS rule “clear: both” do?
The clear property is used to specify which side of floating elements are not allowed to float. It sets or returns the position of the element about floating the objects. The "clear: both" means floating the elements are not allowed to float on both sides. It is used when no need for any element to float on the left and right side as related to the
1 min read
PHP | Imagick clear() Function
The Imagick::clear() function is an inbuilt function in PHP which is used to clear all resource allocated to an Imagick object. Syntax: bool Imagick::clear( void ) Parameters: This function does not accept any parameter. It just clears off the resources of the Imagick object which is used to call the function. Return Value: This function returns tr
2 min read
PHP | Ds\Collection clear() Function
The Ds\Collection::clear() function is an inbuilt function in PHP which is used to remove all values from the collection. Syntax: Ds\Collection::clear( void ) Parameters: This function does not accepts any parameters. Return Value: This function does not return any value. Below programs illustrate the Ds\Collection::clear() function in PHP: Example
1 min read
jQWidgets jqxListBox clear() Method
jQWidgets is a JavaScript framework for making web-based applications for PC and mobile devices. It is a very powerful, optimized, platform-independent, and widely supported framework. The jqxListBox is used to illustrate a jQuery ListBox widget which comprises a list of electable elements. The clear() method is used to clear all items from the jqx
2 min read
PHP | DS\Map clear() Function
The DS\Map::clear() function of the Map class in PHP is used to clear a Map object. That is it deletes all of the values from a given Map object. It does not delete the Map, it just removes all of the values from the Map object. Syntax: void public Ds\Map::clear ( void ) Parameter: It does not accepts any parameter. Return value: This function does
1 min read
PHP | Ds\Vector clear() Function
The Ds\Vector::clear() function is an inbuilt function in PHP which is used to clear the vector elements by removing all the elements from the vector. Syntax: void public Ds\Vector::clear( void ) Parameters: This function does not accept any parameter. Return Value: This function does not return any value. Below programs illustrate the Ds\Vector::c
1 min read
PHP | Gmagick clear() Function
The Gmagick::clear() function is an inbuilt function in PHP which is used to clear all resources associated to Gmagick object. Syntax: Gmagick Gmagick::clear( void )   Parameters: This function does not accepts any parameter. Return Value: This function returns the cleared Gmagick object. Errors/Exceptions: This function throws GmagickException on
2 min read
PHP | Ds\Set clear() Function
The Ds\Set::clear() function is an inbuilt function in PHP which is used to remove all values from the set. Syntax: void public Ds\Set::clear( void ) Parameters: This function does not accept any parameter. Return value: This function does not return any value. Below programs illustrate the Ds\Set::clear() function in PHP: Program 1: <?php // De
1 min read
PHP | Ds\Deque clear() Function
The Ds\Deque::clear() function is an inbuilt function in PHP which is used to clear the Deque by removing all elements from the Deque. Syntax: public Ds\Deque::clear( void ) : void Parameters: This function does not accepts any parameter. Return Value: This function does not return any Value. Below programs illustrate the Ds\Deque::clear() function
2 min read
PHP | Ds\Stack clear() Function
The Ds\Stack::clear() function of PHP is used to remove all elements from a Stack and clear it. This function simply removes all of the elements from the Stack but not completely deletes it. It just empties it. Syntax: void public Ds\Stack::clear ( void ) Parameters: This function does not accept any parameters. Return Value: This function does not
2 min read
HTML DOM Local Storage clear() Method
The clear() method removes all the Storage Object items for the current domain. Syntax: localStorage.clear() Property Values: No Property Values Example: Set item, clear, and display for the current domain. C/C++ Code &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;style&gt; body { text-align: center; } h1 { colo
2 min read
PHP Ds\PriorityQueue clear() Function
The Ds\PriorityQueue::clear() Function in PHP is used to clear all of the elements from a PriorityQueue instance. This function just clears the instance without deleting it. Syntax: void public Ds\PriorityQueue::clear ( void ) Parameters: This function does not accepts any parameters. Return Value: This function does not returns any value. Below pr
1 min read
PHP Ds\Queue clear() Function
The Ds\Queue::clear() Function in PHP is used to clear all of the elements from a Queue instance. This function just clears the instance without deleting it. Syntax: void public Ds\Queue::clear ( void ) Parameters: This function does not accepts any parameters. Return Value: This function does not returns any value. Below programs illustrate the Ds
1 min read
p5.js clear() function
The clear() function in p5.js is used to clear the pixels within a buffer. This function only clears the canvas. This function clears everything to make all of the pixels 100% transparent. It can be used to reset the drawing canvas. Syntax: clear() Parameters: This function does not accept any parameter. Below program illustrates the clear() functi
1 min read
D3.js | d3.set.clear() Function
The set.clear() function in D3.js is used to remove all values from the set. It clears the set and holds that blank set you can check that in the 2nd example. Syntax: d3.set().clear(); Parameters: This function does not accept any parameters. Return Value: This function does not returns any values. Below programs illustrate the d3.set.clear() funct
2 min read
D3.js | d3.map.clear() Function
The map.clear() function in D3.js used to remove all the entries from the created map. Syntax: d3.map.clear(); Parameters: This function does not accept any parameter. Return Value: This function does not return any values. Below programs illustrate the d3.map.clear() function in D3.js: Example 1: <!DOCTYPE html> <html> <head>
2 min read
PHP | Ds\Pair clear() Function
The Ds\Pair::clear() function is an inbuilt function in PHP which is used to remove all values from the pair. Syntax: void Ds\Pair::clear( void ) Parameters: This function does not accept any parameters. Return Value: This function does not return any value. Below programs illustrate the Ds\Pair::clear() function in PHP: Program: <?php // Create
1 min read
HTTP headers | Clear-Site-Data
The HTTP header Clear-Site-Header is a response-type header. This header is used in deleting the browsing data which is in the requesting website. These browsing data includes cache, cookies, storage and executionContents. It helps the web developers to have an improved level of control over data stored by the browser locally. Syntax: Clear-Site-Da
2 min read
PHP | ImagickDraw clear() Function
The ImagickDraw::clear() function is an inbuilt function in PHP which is used to clear the ImagickDraw object of any accumulated commands, and resets the settings it contains to their defaults. Syntax: bool ImagickDraw::clear( void ) Parameters: This function doesn’t accepts any parameter. Return Value: This function returns TRUE on success. Except
2 min read
Node.js console.clear() Method
The console.clear() method is used to clear the stdout, when stdout is a TTY (Teletype) i.e. terminal it will attempt to clear the TTY. When stdout is not a TTY, this method does nothing. The console.clear() will work differently across different operating systems and terminal types. For Linux operating systems, console.clear() operates like the cl
1 min read
How to set, clear and toggle a single bit of a number in JavaScript?
Given a JavaScript number and the task is to set, clear and toggle a single bit of any number. Here are few approaches discussed with the help of JavaScript. Setting the bit: Get the position of the bit to be set(starts from right, first bit is at 0 position), Ex. (bitSet = 3) Get the mask by mask = 1 << setBit, this mask is helpful in settin
3 min read
How to clear the canvas using clearRect in HTML ?
The clearRect() method of the Canvas 2D API which is used to erase the pixel in a rectangular area by setting the pixel color to transparent black (rgba(0, 0, 0, 0)).Syntax: abc.clearRect(x, y, width, height); Parameters: x, y: These parameter represents the top-left coordinate of the rectangular box.width: It is used to set the width of the rectan
2 min read
How to clear form after submission in Angular 2?
In Angular 2, they are two types of forms: Template-driven forms. Reactive forms. In template-driven forms, most of the content will be populated in .html file.In Reactive forms, most of the functionalities and content will be performed in .ts file. The main advantage of reactive forms is, we can create custom validations and the second pivotal adv
2 min read
ASP Clear Method
The ASP Clear Method is used to clear or erase an Buffered HTML Output. This method only erases the response Body, It does not affect the response Headers. When the Response.buffer is set to false, It will show an error message after calling. Syntax: response.Clear Parameter Values: It does not contain any parameters. Return Values: This method hav
1 min read
p5.js TypedDict clear() Method
The clear() method of p5.TypedDict in p5.js is used to remove all the key-value pairs in the typed dictionary. A key-value pair is a set of two values that are mapped to each other. These values can be accessed by querying this dictionary using the key portion of the pair. A typed dictionary can store multiple key-value pairs that can be accessed u
2 min read
three90RightbarBannerImg