Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

clear — moving a block below floats

The clear property specifies which earlier floats must be above a block. Apply it to the element that should no longer sit beside a float.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

clear: none | left | right | both | inline-start | inline-end;
/* Also accepts CSS-wide keywords. */

clear applies to block-level elements. In horizontal writing modes, left moves the block below earlier floats on the left, right below floats on the right, and both below floats on either side. The initial value none adds no such constraint; the property is not inherited.

The browser may add clearance, affecting margin collapsing. Only earlier floats in the same block formatting context count, not descendants of the cleared element. clear does not turn off their float.

CSS Writing Modes defines left and right here as the line-left and line-right sides, respectively. In vertical writing modes, these can correspond to the top and bottom. The logical values inline-start and inline-end instead select the start and end sides of the inline axis, respectively, according to the containing block’s writing mode and text direction. CSS-wide keywords such as inherit and initial are also available.

Examples

<!doctype html>
<meta charset="utf-8">
<title>clear</title>
<style>
  .demo { display: flow-root; width: 240px; }
  .float { float: left; width: 80px; height: 60px; background: skyblue; }
  .next { clear: both; height: 20px; background: gold; }
</style>
<div class="demo">
  <div class="float">A</div>
  <div class="next">B</div>
</div>

Result

B.top - A.top = 60 CSS px; B.top = A.bottom.

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources