Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • CSS Tutorial
  • CSS Exercises
  • CSS Interview Questions
  • CSS Selectors
  • CSS Properties
  • CSS Functions
  • CSS Examples
  • CSS Cheat Sheet
  • CSS Templates
  • CSS Frameworks
  • Bootstrap
  • Tailwind
  • CSS Formatter
Open In App
Next Article:
Explain the concept of the CSS Flexbox
Next article icon

Explain the purpose of clearing floats in CSS

Last Updated : 25 Aug, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we will learn to clear float and the purpose of clearing floats in CSS. Before diving into this topic, we will know the float property in CSS. The float property in CSS is used to change the normal flow of an element. The float property defines where should be an element place container's left or right side.

Purpose of clearing floats in CSS: We clear the float property to control the floating elements by preventing overlapping. On our webpage, if an element fits horizontally next to the floated elements, unless we apply the clear property same as float direction then the elements will be a move below the floated elements. 

Syntax:

clear: none|right|left|both|initial|inherit;

Property values:

  • none: It is the default value of the clear property. After using this value the element will not be pushed left or right floated elements.
  • right: This value pushes the element right below the floated elements.
  • left: This value pushes the element left below the floated elements.
  • both: This value pushes the element left and right to the floated elements.
  • initial: Change the properties to their default value.
  • inherit: Inherit the floating properties to their parent element.

The best way to understand the concept of clear is by using an example. 

Example 1: We have floated an image on the left of a text as shown below. We can see that the element is pushed left to the image because of using the float property. 

HTML
<!DOCTYPE html> <html>  <head>     <style>         img {             float: left;         }     </style> </head>  <body>     <h1>The clear Property</h1>     <img src= "https://media.geeksforgeeks.org/wp-content/cdn-uploads/20190710102234/download3.png"         width="100" height="132" />      <p>         The content will be shown          left to the image.     </p> </body>  </html> 

Output:

Example 2: Once we use clear property with left value, the element will be pushed below the image.

HTML
<!DOCTYPE html> <html>  <head>     <style>         img {             float: left;         }          p {             clear: left;         }     </style> </head>  <body>     <h1>The clear Property</h1>     <img src= "https://media.geeksforgeeks.org/wp-content/cdn-uploads/20190710102234/download3.png"         width="100" height="132" />      <p>         The content will be shown          left to the image.     </p> </body>  </html> 

Output:


Next Article
Explain the concept of the CSS Flexbox
author
vikashgautam11
Improve
Article Tags :
  • Web Technologies
  • CSS
  • CSS-Questions

Similar Reads

  • Explain the term “pseudo-class” in CSS3
    Cascading Style Sheets referred to as CSS is a stylesheet language used to design and describe the presentation of the webpage to make it attractive. The main use of CSS is to simplify the process of making web pages presentable. The way elements should be rendered on screen is described by CSS. CSS
    4 min read
  • Explain the concept of the CSS Flexbox
    The CSS Flexbox (Flexible Box) model is a layout mechanism that provides a straightforward and efficient way to design complex, responsive, and dynamic web layouts. Introduced to address challenges posed by traditional layout models, Flexbox simplifies the alignment and distribution of space among i
    2 min read
  • Explain the concept of specificity in CSS
    Prerequisites: CSS syntax and selectors , HTML basics Specificity is an advanced algorithm used by HTML browsers to define the CSS declaration which will be the most appropriate to an HTML element. It basically calculates the weights of all the CSS selectors to determine the proper rule. The main go
    3 min read
  • Explain the positions property in CSS
    In this article, we will see what is position property, and how to use this property wisely in order to make web pages. The CSS position property is used to align the different elements in the HTML page. CSS position property plays an important role to make high-quality web pages. The CSS position p
    6 min read
  • How to prevent parents of floated elements from collapsing in CSS?
    It is known that HTML elements like div, paragraphs, texts, etc. grow to fit the content of their child. But if the child of those elements is floated either to the right or left then the parents may collapse. That is, they will lose their actual behavior. Let's understand this with an example: Cons
    4 min read
  • HTML Clearing the input field
    Clearing an input field in HTML involves removing any text or data entered by the user within a form. This can be done programmatically using JavaScript by setting the field’s value property to an empty string, which effectively erases its contents. Methods to Clear Input Fields in HTMLThere are som
    5 min read
  • What is the purpose of .media-list class in bootstrap ?
    In this article, we will learn the use of the '.media-list' class in Bootstrap. The .media-list class is one of the media object classes of bootstrap. The '.media' class is used to align or float the media items like audio, video, and images, While the '.media-list' class, is used when the media ite
    4 min read
  • How to Clear Floats with the "clearfix" hack?
    Adjusting the elements in the application is important, especially when dealing with floating elements that can disrupt the layout. In this article, we will explore two different approaches to clear floats with the clearfix hack. Below are the possible approaches: Table of Content Using a Separate C
    3 min read
  • What are the various techniques for clearing floats in CSS ?
    In this article, we will learn various techniques for clearing float. Before diving into this topic, we will know the float property in CSS. The float property in CSS is used to change the normal flow of an element. The float property defines where should be an element positioned (right or left) in
    5 min read
  • Explain the working of the Block Formatting Context
    What is Block Formatting Context (BFC)? Block Formatting Context is a layout concept used in CSS to determine the position and size of elements on a webpage. It is used to control the layout of elements on a webpage, such as positioning elements in a specific location and controlling the size of ele
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences