Using the CSS property “float”, an element can be moved to the left or right inner edge of its parent element. The special feature is that the “clear” property can be used to specify whether subsequent content should flow around the element or form an independent section.
The CSS property “float” specifies how an element should float, and the property “clear” specifies which elements can float next to the “cleared” element and on which side.
Float Left
Float Right
The “float” Property
The float property is used to position and format content, e.g. to float an image to the left of the text within 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 (it is displayed exactly where it occurs in the text)
- inherit - The element inherits the float value of its parent element
Examples
img { float: left; }
This paragraph shows how text flows around an image that has been placed on the left with float: left. The dandelion stays on the left while the lines continue to its right and use the full width again below the image. This lets you embed photos, graphics or info boxes into running text without extra columns or tables. The space between image and text is set with margin-right, the space below with margin-bottom. If the text is shorter than the image, the next element moves up next to the image – this is exactly where clear comes in, pushing the following block back below the floated element. Try it out: resize your browser window and watch how the text rearranges itself around the dandelion.
img { float: right; }

Here the image sits on the right with float: right, and the text flows past it on the left. This variant works well for supporting images that should not interrupt the reading flow: the eye starts with the text and finds the image at the edge as additional information. This time the space to the text is controlled with margin-left. The same rule applies: if the paragraph is too short, the image reaches into the next section. An element with clear: right or clear: both makes sure the following content only starts below the image. On small screens it is often useful to remove the float with a media query so that image and text are stacked and remain easy to read.
Do you have any questions about this topic? Or do you need help designing your website from a professional web agency in Munich? Then feel free to contact us!