Currently Empty: ₹0.00
CSS Clear
CSS Clear
Learn how the CSS clear property controls whether an element can appear beside floated elements. Understand clear, left, right, both and none with practical examples.
📘 What is CSS Clear?
The CSS clear property is used with floated elements. It specifies on which sides of an element other floated elements are not allowed.
In simple words, clear tells an element: “Do not move beside a floated element.”
Important:
The clear property is mainly used to control the effect of
float on following elements.🎯 Why Do We Use Clear?
- To stop an element from appearing beside a floated element.
- To move an element below floated content.
- To control left and right floating elements.
- To prevent unwanted layout overlap.
- To create a clean separation after floated sections.
🧩 CSS Clear Syntax
selector {
clear: value;
}🔑 Clear Property Values
| Value | Meaning |
|---|---|
none | No restriction on floating elements. |
left | Element moves below left-floating elements. |
right | Element moves below right-floating elements. |
both | Element moves below both left and right floats. |
inherit | Inherits the clear value from its parent. |
💻 Example 1: clear: both
The most commonly used value is both.
It prevents the element from appearing beside either
left or right floated elements.
<div class="box">
Floating Box
</div>
<p class="text">
This paragraph comes after the floating box.
</p>
<style>
.box {
float: left;
width: 180px;
height: 100px;
background: steelblue;
color: white;
padding: 20px;
}
.text {
clear: both;
}
</style>▶️ Live Example
The blue box is floated to the left.
The following section uses clear: both,
so it starts below the floated box.
FLOAT: LEFT
This text can flow around the floated element. Because the first element is floated to the left, normal content may appear beside it.
clear: both;
This element starts below the floating element.
This element starts below the floating element.
⬅️ Example 2: clear: left
clear: left prevents an element from appearing
beside a left-floating element.
.box {
float: left;
}
.content {
clear: left;
}➡️ Example 3: clear: right
clear: right prevents an element from appearing
beside a right-floating element.
.box {
float: right;
}
.content {
clear: right;
}↕️ Example 4: clear: both
clear: both clears both left and right floats.
It is useful when a section should always begin below
all floated elements.
.content {
clear: both;
}
Best Practice:
Use
clear: both when you want to make sure
the element clears floats on both sides.📊 Clear Values Comparison
clear: left
Clears left-floating elements only.
clear: right
Clears right-floating elements only.
clear: both
Clears both left and right floating elements.
clear: none
The element is not forced below floats.
🔗 Float and Clear Together
The float property moves an element to the
left or right, while clear controls how
subsequent elements interact with those floats.
.image {
float: left;
margin-right: 20px;
}
.next-section {
clear: both;
}⚠️ Common Mistakes
-
Using
clearwithout understanding the relatedfloat. -
Using
clear: leftwhen both sides need to be cleared. - Forgetting that clear affects the element on which the property is applied.
-
Expecting
clearto remove the float itself.
Remember:
clear does not cancel or remove
float. It controls how the current element
is positioned relative to floated elements.📝 Practice Exercise
Try the following tasks in your HTML Runner:
-
Create a box with
float: left. - Create a paragraph beside the floating box.
-
Add a new section using
clear: left. - Create a right-floating box.
-
Use
clear: righton the next section. - Create both left and right floated boxes.
-
Use
clear: bothto place the next section below them.
📚 Quick Reference
| CSS | Purpose | Example |
|---|---|---|
| clear | Controls interaction with floats | clear: both; |
| clear: left | Clears left floats | clear: left; |
| clear: right | Clears right floats | clear: right; |
| clear: both | Clears both sides | clear: both; |
| clear: none | No clearing | clear: none; |
✅ Key Points to Remember
- clear is commonly used with float.
- left clears left-floating elements.
- right clears right-floating elements.
- both clears floats on both sides.
- clear does not remove the float.
- clear: both is commonly used to start a section below floated content.
SNCEC PORTAL
Student & Website Links
Quick access to student services, courses, learning resources and SNCEC information.
Student Login
Access your student account
Student Registration
Create your student account
Student Dashboard
Manage your learning activities
Courses
Explore our job-oriented courses
All Courses List
View complete course catalog
Instructor Registration
Join us as an instructor
Our Team
Meet our professional team
About Us
Learn more about SNCEC
Contact Us
Get in touch with our team
Mock Tests & Quizzes
Practice and test your knowledge
Student Zone
Access student services and resources
Student Zone →Learning Portal
Access online learning resources
Open Portal →Computer Shop
Computers, accessories & IT products
SNCEC Official Website
Shree Narayan Computers & Education Center



