liveBook · Manning

Float property

As explained in CSS in Depth, Second Edition

A CSS layout mechanism that removes an element from normal flow and positions it toward one side so surrounding content can flow around it.

The float property pulls an element to the left or right edge of its container, removes it from normal flow, and lets surrounding inline content wrap around its margin box. Its vertical position still depends on where the element appears in the HTML. section 14.4.1

Use these rules to predict the rendered result:

  • Apply float: left or float: right to choose the edge around which content flows. section 14.4.1
  • Place the floated element where the wrap should begin; floating does not move it upward or downward from that source location. section 14.4.1
  • Float multiple elements in the same direction to stack them alongside one another. section 14.4.1
  • Account for a float extending beyond its original container, and clear it when later content must stop wrapping around it. section 14.4.1

Wrap poem text around an image

Place an image inside a .poem-image wrapper, then apply float: left and a right margin. The poem’s inline text flows beside the 350-pixel image, producing a newspaper-like layout. The wrapper is optional, but using a normal element can make shapes more predictable than applying them directly to an image. section 14.4.1

Listing 14.14 Floating the image to the left
.poem-image {
  float: left;
  margin-right: 15px;
}

.poem-image > img {
  display: block;
  height: 350px;
  width: 350px;
  object-fit: cover;
}

Inspect the compact CSS listing for the floated image, including direction, spacing, display mode, and dimensions. section 14.4.1

Figure 14.12 Defining a shape causes inline content to flow around the contours of the shape.
figure

Compare ordinary rectangular wrapping with shape-based wrapping when a float is combined with shape-outside. section 14.4

How CSS in Depth, Second Edition covers it

How deep it goes
Explains flow removal, edge placement, source-order dependence, stacking, and container overflow, then stops short of broader float mechanics.
Examples
Demonstrates a floated eagle image beside Emily Dickinson’s poem and shows multiple floats, clipping, and shaped text wrapping.
What it assumes
Assumes basic HTML and CSS, while explaining normal flow, inline wrapping, and the float’s dependence on markup position.
What you can do after
Apply it via CSS to place an image beside text and control whether subsequent content continues wrapping around the float.
How it connects
Connects floats with inline content, shape-outside, masks, clip paths, and border-radius contours.

Also explained in

Compare how 5 books explain float property →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of CSS in Depth, Second Edition. The section links point to the parts of the book it draws on.