๐Ÿš€ LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Expert Masterclasses.
๐ŸŽ“ COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEcss

css Documentation

LOADING ENGINE...

CSS Clear Property

Fix broken layouts and control document flow. Learn how to use clear to manage floating elements.

style.css
/* Fix the layout */
.footer {
background: #333;
clear: both;
}
๐Ÿงน
clear.html
1 / 8
๐Ÿงน

Tutor:The `clear` property in CSS is directly related to floating elements. When elements float, they are removed from the normal flow, causing following elements to wrap around them.


CSS Layout Mastery

Unlock nodes by learning flow control and positioning.

Concept 1: The Float Problem

When elements float, they are removed from the normal document flow. This can cause parent containers to collapse or following elements (like footers) to wrap up beside the floated content unexpectedly.

System Check

What happens to the document flow when an element floats?


Community Holo-Net

Share Layout Tricks

Found a unique way to use clear or clearfix? Share your snippets.

Enjoying this guide?

Codesyllabus is 100% free and open-source. Support our mission, pay for server infrastructure, and fuel new tutorials by buying us a coffee!

CSS Clear Property

Author

Pascual Vila

Frontend Instructor.

The clear property specifies what elements can float beside the cleared element and on which side. It is the primary tool used to fix layout issues caused by float.

The Problem with Floats

When an element is floated, it is taken out of the normal document flow. Following elements will move up and wrap around it. This is great for text wrapping images, but terrible for structural layout, where a footer might suddenly jump up beside a sidebar.

Using clear

The clear property pushes the element down past any floating elements.

  • clear: left - The element cannot sit next to left-floating elements.
  • clear: right - The element cannot sit next to right-floating elements.
  • clear: both - The element cannot sit next to floats on either side.
  • clear: none - Default behavior. The element can sit next to floats.

The "Clearfix" Technique

Often, a parent container collapses to zero height if all its children are floating. To fix this, we apply a "clearfix" to the parent, or simply use overflow: auto or display: flow-root. However, explicitly using a cleared element (like an empty div or a pseudo-element) at the end of the container is the classic method.

CSS Clear Glossary

clear
A CSS property that specifies whether an element can be next to floating elements that precede it or must be moved down (cleared) below them.
float
A CSS property that places an element on the left or right side of its container, allowing text and inline elements to wrap around it.
Clearfix
A technique (usually involving pseudo-elements) used to force a container to expand to contain its floating children.
Document Flow
The way elements are displayed in a web page. Floated elements are removed from the normal flow, while cleared elements restore it.