Clear - CSS Property
Summary of characteristics of the clear property
none | left | right | both | inline-start | inline-end | block-start | block-endnoneDiscrète: during an animation, the clear property passes from one value to another without transition.Single: single value (no order).Syntax diagram of clear.
clear property.The links in the diagram provide more details about the values.
Download the diagram.
Description of the clear property.
clear indicates whether the element is allowed to be next to the floating elements that come before it.
This property complements the float property. It limits the effect on the element that receives the clear property. When an element
is set to float, the following elements can position themselves next to it. This is sometimes referred to as wrapping. This can apply to several elements,
as long as there’s space available next to the floating element. The clear property prevents an element from sitting next to a floating element.
Special case of a floating element larger than the text.
Let's take the case of a series of floating elements accompanied by their explanatory text. These floating elements are of different sizes, or it could be that the text is more or less long. So it can happen that the floating element is taller than the text that goes with it. In that case, the second image will end up next to the first one, since there is space left. The result doesn't look very good, and in any case, it's not the expected outcome.
To solve the problem and get back a proper list, you just need to apply the clear property to the container. This technique is often
called clearfix. However, it has a problem when the container has a background or a border (as you can see in our example).
The description2 class is applied to the container, and the description2a class to the image.
clear property applied to the container, this second paragraph is correctly positioned.
Note that there's another method: apply the display property to the container with the value flow-root.
display applied to the container with the value flow-root also fixes the problem.
Language support.
Logical values like inline-start or inline-end allow you to take writing direction into account depending on the language.
leftrightValues for clear.
- clear: none;
Default value. Allows floating. This item can sit next to floating items if there are any before it.
Floating element.This paragraph is next to the floating element.This second paragraph gets the property
clearwith the valuenone. It also sits next to the floating element.clear:none; - clear: left;
Does not allow floating elements on the left that come before it. But the element can sit next to floating elements on the right if any exist before it.
Floating element.This paragraph is next to the floating element.This second paragraph gets the property
clearwith the valueleft. It doesn't sit next to the floating elements to the left that come before it.clear:left; - clear: right;
Symmetric to the previous value: does not allow floating elements on the right that come before. But it doesn't prevent placement next to floating elements on the left.
Floating element.This paragraph is next to the floating element.This second paragraph gets the property
clearwith the valueleft. It doesn't sit next to the floating elements to the right that come before it.clear:right; - clear: both;
Does not allow the floating elements that come before. The element positions itself against the margin, below any floating elements, as if they weren't floating.
Floating element 1.Floating element 2.This paragraph is next.This second paragraph gets the property
clearwith the valueboth. It doesn’t sit next to any left-floating or right-floating elements that come before it.clear:both; - clear: inline-start; clear: inline-end;
These two values are equivalent to
leftandrightfor Latin languages, but adapt to the writing direction for non-Latin languages such as Arabic or CJK languages.Floating element.This paragraph is next to the floating element.This second paragraph gets the property
clearwith the valueinline-start. It doesn't sit next to the left-floating elements that come before it, but it depends on the language.clear:inline-start; - clear: block-start; ⚠ clear: block-end; ⚠
These two values are not currently supported by any browser.
- clear: initial; (
none) clear: inherit; clear: revert; clear: revert-layer; clear: revert-rule; clear: unset;These values are described in more detail on their respective page:
initial,inherit,revert,revert-layer,revert-rule,unset.
Access the clear property via a program
With Javascript, change the value of clear.
Floating elements are determined by two properties: clear and float. Here's how to change the value of clear
with JavaScript. This language allows two syntaxes: the first uses the typical CSS notation, using the style array, and the second syntax is more common
in object-oriented languages.

let el = document.getElementById('id');
el.style['clear'] = 'left';
// or
let el = document.getElementById('id');
el.style.clear = 'left';
With Javascript, read the value of clear.
For this code to work, the property must have been applied directly to the element itself via its style attribute (that's what the previous
code does), and not through a CSS selector.

let el = document.getElementById('id');
let value = el.style['clear'];
// or
let el = document.getElementById('id');
let value = el.style.clear;
With Javascript, read the computed value of clear.
The computed value is the one that comes from the chain of inheritances. It's always defined; at worst, it's the property's initial value.

let el = document.getElementById('id');
let value = window.getComputedStyle(el).getPropertyValue('clear');
With JQuery, read or change the value of clear.
JQuery also offers two syntaxes to define or reread the clear property.

// Read the value:
$('#id').prop('clear');
// Write the value:
$('#id').prop('clear', 'left');
$('#id').prop('{clear': 'left'});
With JQuery, read the computed value of clear.

let value = $('#id').css('clear');
Other code examples.
You can find other examples of Javascript and JQuery code on the page Javascript and CSS: adding style sheets, adding or removing classes, etc.
Test it yourself.
By clicking the buttons below, you apply the entered value to the clear property and then display either the value as it was applied or the
computed value. The second option lets you see how the value of clear is stored (serialized). Since the property only accepts predefined values,
there won't be any difference between these two values for the clear property, unless the assigned value is incorrect. In that case, the
assigned value is null, and the computed value reverts to the initial value (none).
Simulator.
The first image is set to float on the left (float:left); the second image, on the other hand, floats on the right.
The two text paragraphs either "slip" between the two images or not, depending on the value of their clear property.
Browsers compatibility with clear.
All current browsers handle the clear property correctly in its initial definition. When it comes to the level 3 definition of the specification,
there are still some issues with the new values, especially block-start and block-end.
clear property to prevent an element from floating.clearproperty
(CSS2)
Browsers on computers :
Mobile browsers :
Outdated or marginal browsers :

Internet Explorer

UC Browser pour Androïd

Opéra Mobile

QQ Browser

Baidu Browser

Samsung Internet

Edge

Firefox

Chrome

Safari sur IOS

KaiOS Browser

Opéra

Safari

Androïd Brower

Chrome pour Androïd

Firefox pour Androïd

Opéra mini
Historic of the clear property.
-
Cascading Style Sheets specification - Version 1
This first level of the CSS specification describes the mechanism of cascading style sheets. Authors and readers can add styles to documents. Mainly intended for formatting HTML documents, CSS allows defining colors, fonts, text formatting, spacing (margins), etc. The CSS language is easy to understand, readable, and easy to write; it uses common terms from desktop publishing.
Regardingclear:
Initial definition of thefloatproperty (first specification of the CSS language).November 17, 1995Working Draft.November 12, 1996Proposed for recommendation.December 17, 1996Recommendation .September 13, 2018Old specification, declared obsolete. -
Cascading Style Sheets Level 2 - Revision 1 Specification
This level 2 of the specification describes the mechanism of cascading styles in CSS. This language is used to format HTML or XML documents. It supports media-specific style sheets so that authors can adapt the presentation of their documents for visual browsers, auditory devices, printers, braille devices, portable devices, etc.
Regardingclear:
Acceptance of theinheritvalue.November 04, 1997Working Draft.March 24, 1998Proposed for recommendation.May 11, 1998Recommendation . -
CSS Logical Properties and Values Level 1
This specification module defines properties that indirectly define certain other properties depending on the writing mode: left to right, right to left, or top to bottom. They are useful in simple and generic style sheets, such as browser style sheets, but can also save a few lines of styles for documents containing both left-to-right and right-to-left text.
Regardingclear:
Additional details on the logical values accepted byclear.May 18, 2017Working Draft. -
CSS Page Floats Level 3
Regardingclear:
Adding logical valuesinline-startandinline-end.
Accepting new values for vertical write modestop,block-start, etc.September 15, 2015Working Draft.
See also, about floating elements.
The concept of floating elements has existed for a long time and has been described in many specifications. The most current definitions can be found in the CSS Page Floats module.




