Skip to main content

The CSS float Property

The float property sets how an element floats within its container. It places the element on the left or right side, letting text and inline elements wrap around it.

It can take these values:

  • left — the element floats to the left of its container.
  • right — the element floats to the right of its container.
  • none — the default. The element does not float and stays where it appears in the text.
  • inherit — the element takes the float value of its parent.

Tip: The float property is often used to wrap text around images.


CSS float: right Example

float: right floats an element to the right of its container.

Tip: Make the window smaller to see the text wrap around the floated element.

Example

The box floats to the right and the text wraps around its left side.

Prompt
An HTML page showing float: right, with text wrapping around a floated box. In an internal <style> block, float a colored box (stand-in for an image) to the right with some left margin. Add a paragraph of text that wraps around the left of it.
Output: complete HTML page

CSS float: left Example

float: left floats an element to the left of its container.

Example

The box floats to the left and the text wraps around its right side.

Prompt
An HTML page showing float: left, with text wrapping around a floated box. In an internal <style> block, float a colored box (stand-in for an image) to the left with some right margin. Add a paragraph of text that wraps around the right of it.
Output: complete HTML page

CSS float: none Example

float: none means the element does not float and stays in the normal flow.

Example

The box stays in the normal flow and the text does not wrap around it.

Prompt
An HTML page showing float: none, where the box stays in the normal flow. In an internal <style> block, set a colored box (stand-in for an image) to float none. Add a paragraph; the text does not wrap around the box.
Output: complete HTML page

CSS Float Next To Each Other

Floating several elements left makes them line up next to each other.

Example

Three colored divs are floated left so they sit side by side.

Prompt
An HTML page showing several boxes floated next to each other. In an internal <style> block, float div elements left with 15px padding, and give .div1 a red background, .div2 yellow, and .div3 green. Add three divs so they sit side by side.
Output: complete HTML page