CSS Layout - float and clear

The CSS float property specifies how an element should float. The CSS clear property specifies what elements can float beside the cleared element and on which side.


The float Property

The float property is used for positioning and formatting content, for example, letting an image float beside text in a container.

The float property can have one of the following values:

  • left - The element floats to the left of its container
  • right - The element floats to the right of its container
  • none - The element does not float (default)
  • inherit - The element inherits the float value of its parent

Example - float: right;

The following example shows how an image floats to the right of some text:

Output :

Example - Float Next To Each Other

Normally, div elements are stacked vertically. But with float: left, we can make them sit side by side.

Output :