CSS

CSS Clear Property: Syntax, Usage, and Examples

The CSS clear property is a key component of controlling element positioning and layout, especially in conjunction with floated elements. When using float-based layouts, it's common for overlapping or collapsed elements to occur unless explicitly handled. The CSS clear property helps resolve such layout issues by forcing elements to avoid sitting next to floated elements, essentially creating a clean break in the flow of content.


What Is the CSS Clear Property?

The CSS clear property specifies whether an element should be moved below (cleared of) floated elements that precede it. It prevents elements from wrapping around or beside floated content, maintaining the structural integrity of your layout.

When you float elements using the float property (e.g., float: left or float: right), the rest of the content will wrap around them. If you want an element to avoid being positioned beside a float, you apply the clear property to push it downward.

Basic Syntax

selector {
  clear: none | left | right | both | inherit;
}
  • none (default): The element can be next to floated elements.
  • left: Clears floats on the left side.
  • right: Clears floats on the right side.
  • both: Clears both left and right floats.
  • inherit: Inherits the clear property value from its parent.

The Need for Clearing Floats

The CSS clear property is most useful when working with floated layouts or components. Without clearing, floated elements may cause visual issues such as overlapping content, collapsed parent containers, or broken layout structures.

Example Without Clear

<div class="float-left">Floated Left</div>
<div class="content">This content wraps beside the floated element.</div>

Here, the .content div will appear next to .float-left.

Example With Clear

.content {
  clear: both;
}

Now, the .content element is pushed below the floated content, keeping the layout clean.


Practical Usage of the CSS Clear Property

Example: Clearing Left Float

.clear-left {
  clear: left;
}

Use this when you only need to clear elements floated to the left side.

Example: Clearing Right Float

.clear-right {
  clear: right;
}

Applies only to elements floated to the right.

Example: Clearing Both Sides

.clear-both {
  clear: both;
}

This is the most common use case, especially when resetting the flow of content after two-column layouts.


Typical Scenario in Multi-Column Layouts

Imagine you have two columns floated left and right respectively, and a footer underneath:

<div class="left-col">Left</div>
<div class="right-col">Right</div>
<div class="footer">Footer</div>

Without applying clear: both; to the .footer, it may appear beside the floated columns instead of below them.

.footer {
  clear: both;
}

This ensures the footer clears both floated columns and occupies its own horizontal space.


Combining Clear Property with Float

You often see the clear property used in combination with float-based designs. A common method to control layout involves floating elements (like sidebars) and then using the clear property to ensure subsequent content doesn’t wrap around them.

Sidebar Example

.sidebar {
  float: left;
  width: 25%;
}

.main {
  float: right;
  width: 70%;
}

.clearfix {
  clear: both;
}

Applying the clearfix below both floated elements restores the flow.


The Clearfix Hack

While the CSS clear property works well, it’s typically used on the element that comes after the floated elements. However, sometimes parent containers collapse when they only contain floated children.

To fix this, you use a clearfix technique:

.clearfix::after {
  content: "";
  display: table;
  clear: both;
}

Then add the class to the parent element:

<div class="container clearfix">
  <div class="left">Floated Left</div>
  <div class="right">Floated Right</div>
</div>

This allows the container to expand around the floated children.


Limitations of the CSS Clear Property

  • Only relevant when floats are in use. It does not affect flexbox, grid, or absolute positioning.
  • Cannot selectively ignore specific floats—only side-based.
  • Overuse may result in unnecessary layout breaks.

As more modern layout systems emerge, the use of the CSS clear property is declining, but it's still valuable for maintaining or debugging legacy codebases.


Common Use Cases

1. Resetting Layout Flow

After using multiple floated elements, apply clear: both; to ensure new content starts on a new line.

2. Separating Footer Sections

A common mistake is forgetting to clear floated columns, causing the footer to appear beside them instead of underneath.

.footer {
  clear: both;
}

3. Inline Images and Text

When floating images next to paragraphs, sometimes you want a new section of text to begin underneath the image. Use clear: left; for this.


What Is CSS Clear Property Used For?

In essence, the CSS clear property is used to ensure proper vertical flow in layouts that rely on floated content. If an element comes after a float and should not appear beside it, applying clear ensures it respects that rule.

This makes the property useful for:

  • Maintaining layout structure.
  • Preventing text wrapping when not desired.
  • Fixing container collapse issues.
  • Structuring older grid systems before Flexbox and CSS Grid.

Alternatives to Float and Clear in Modern CSS

As layout techniques evolve, Flexbox and CSS Grid have largely replaced float/clear systems.

Flexbox Example

.container {
  display: flex;
}

This removes the need for floats entirely, letting you control layout via alignment, spacing, and direction properties.

Grid Example

.container {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

Even so, the clear property may still be used in legacy designs or simple content flows.


Best Practices When Using CSS Clear Property

  1. Use clear with purpose: Apply only when an element must start after a floated one.
  2. Use clearfix for containers: To avoid layout collapse.
  3. Avoid excessive nesting: Float and clear combinations can get messy if overused.
  4. Pair with modern techniques: Use clear as a fallback or in isolated float contexts.

Accessibility and Clear Property

While the clear property itself doesn’t directly impact accessibility, improper float and clear usage can create confusion in content order. Ensure your document structure and semantic HTML align with the visual layout for screen reader users.


CSS Clear Property vs Overflow and Display

Some developers use overflow: hidden; or display: flow-root; on containers as an alternative to clearing floats.

Example with Overflow

.container {
  overflow: hidden;
}

This forces the container to encompass floated children without needing additional markup or clearfix classes.

Example with Flow-Root

.container {
  display: flow-root;
}

Introduced in newer CSS specifications, flow-root creates a new block formatting context, resolving float-related collapse automatically.


Summary

The CSS clear property is essential for controlling layout flow in float-based designs. It ensures that elements appear beneath floated content rather than beside it, preserving the intended structure of your page. Although modern CSS has largely shifted to Flexbox and Grid, knowing how and when to use the clear property remains valuable—especially when working with legacy code or simple layouts involving floated images or sidebars.

From resetting layout flow to creating structural boundaries between components, the clear property CSS syntax offers a simple yet powerful way to manage float behaviors. With proper use and modern alternatives like clearfix and flow-root, your layout remains stable, clean, and visually consistent.

Learn CSS for Free
Start learning now
button icon
To advance beyond this tutorial and learn CSS by doing, try the interactive experience of Mimo. Whether you're starting from scratch or brushing up your coding skills, Mimo helps you take your coding journey above and beyond.

Sign up or download Mimo from the App Store or Google Play to enhance your programming skills and prepare for a career in tech.

You can code, too.

© 2025 Mimo GmbH

Reach your coding goals faster