Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

float — wrapping text around a box

The float property moves a box to one side so nearby text lines can wrap around it. Learn float directions, the difference between clear and flow-root, and how to check a small example.

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

Syntax

float: none | left | right | inline-start | inline-end;

float removes a box from normal flow but shortens nearby text lines to make room for it. left places it on the left and right on the right; text wraps on the opposite side. none disables floating, is the initial value, and is not inherited.

inline-start and inline-end select the start and end of the line according to writing direction. In horizontal LTR writing they correspond to left and right; in RTL they are reversed. The syntax shown covers common text-wrapping values, not experimental page-related extensions.

clear: both moves a subsequent block box below earlier floats on either side in the same block formatting context. Setting display: flow-root on the parent establishes a new such context and allows its automatic height to include internal floats. This serves a different purpose from moving a particular element below a float.

In the example, A occupies a 60px × 60px light-blue box on the left. Text wraps beside it with a 12px gap and continues below if needed. B starts below the float, and the border encloses the content. Exact line breaks are not part of the expected result.

Examples

<!doctype html>
<meta charset="utf-8">
<title>float</title>
<style>
  .article {
    display: flow-root;
    width: 240px;
    font: 16px/20px monospace;
    border: 1px solid black;
  }
  .badge {
    float: left;
    width: 60px;
    height: 60px;
    margin-right: 12px;
    background: lightblue;
  }
  .after { clear: both; }
</style>
<div class="article">
  <div class="badge">A</div>
  Text wraps beside the floating box and continues below it when necessary.
  <div class="after">B</div>
</div>

Result

A appears in a 60px × 60px light-blue box on the left. Text wraps to its right with a 12px gap and continues below if needed. B starts below the float. The article border encloses the content.

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