Floats and text wrapping

W3C CSS Snapshot 2026

Use a float to place an illustration beside text. Then control which content wraps around it and whether its parent encloses it.

On this page

Wrap text around a floated box

float: left places the box on the left and lets nearby lines wrap around it. clear: left moves a block below earlier left floats.

How to try it Save this example as a new .html file, then open it in your browser. After a change, save and reload.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Wrap text around a floated box</title>
  <style>
aside { float: left; width: 6rem; height: 5rem; margin: 0 1rem 0.5rem 0; background: #def5f5; color: #123; }
.details { clear: left; }
  </style>
</head>
<body>
<aside>Room 2</aside>
<p>Bring your workshop materials.</p>
<p class="details">Doors open at 9 a.m.</p>
</body>
</html>

What to expect The first paragraph sits beside the room label. The second starts below it. Remove clear to compare.

Keep the float inside its parent

A tall float can extend below a parent whose normal-flow content is short. display: flow-root establishes a formatting context and its height includes the float.

How to try it Save this example as a new .html file, then open it in your browser. After a change, save and reload.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Keep the float inside its parent</title>
  <style>
article { display: flow-root; border: 2px solid teal; padding: 8px; }
aside { float: left; width: 6rem; height: 5rem; margin-right: 1rem; background: #def5f5; color: #123; }
  </style>
</head>
<body>
<article><aside>Room 2</aside><p>Workshop check-in</p></article>
</body>
</html>

What to expect The border encloses the room label. Remove flow-root to see the label extend below the border.

Official references