Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Box Model and Sizing

The float property

Reference for the CSS float property: push an element to the left or right so text wraps around it. Values, clearing floats, modern alternatives and examples.

The float property takes an element out of the normal flow and pushes it to the left or right edge of its container. Following inline content, such as text, flows around it. Floats were designed for the classic magazine layout where a picture sits in a column of text, and that is still the best use for them today.

CSS
.portrait {
  float: left;
  margin: 0 1rem 0.5rem 0;
}

Try it

Text wrapping around a floated box

Syntax

CSS
float: none | left | right | inline-start | inline-end
  • Initial value: none
  • Applies to: all elements, but not positioned elements with position: absolute or fixed
  • Inherited: no
  • Animatable: no (discrete)
  • Computed value: as specified, except that a float forces display to a block-level value (for example inline becomes block)

Values

Value Description
none The element is not floated.
left Floats to the left edge of its containing block.
right Floats to the right edge.
inline-start Floats to the start edge of the writing direction (left in left-to-right text, right in right-to-left).
inline-end Floats to the end edge of the writing direction.

Usage notes

  • Floats are removed from the flow. The parent does not grow to contain a floated child, so a container holding only floats collapses to zero height. Fix it with display: flow-root on the parent (the modern clearfix), or place a cleared element after the floats.
  • Order matters. Put the floated element before the text that should wrap around it in the HTML.
  • Float width. A float with no width shrinks to fit its content.
  • Use logical values inline-start and inline-end for layouts that must work in right-to-left languages.
  • Wrap around a shape. Together with shape-outside a float can make text follow a circle or polygon.
  • Not for page layout. Flexbox and grid replace the old float-based columns, giving alignment, gaps and equal heights that floats cannot.
  • Bad for interaction. Do not float form controls or list items to build rows when display: flex would do the job more reliably.

Browser support

Supported in every browser. The logical values inline-start and inline-end are supported in current versions of all major browsers.