Cheap VPS & Xen Server

Residential Proxy Network - Hourly & Monthly Packages

CSS Float

The CSS float property is a positioning property. It is used to push an element to the left or right, allowing other element to wrap around it. It is generally used with images and layouts.

To understand its purpose and origin, let’s take a look to its print display. In the print display, image is set into the page such that text wraps around it as needed.


Its web layout is also just similar to print layout.


How it works

Elements are floated only horizontally. So it is possible only to float elements left or right, not up or down.

  1. A floated element may be moved as far to the left or the right as possible. Simply, it means that a floated element can display at extreme left or extreme right.
  2. The elements after the floating element will flow around it.
  3. The elements before the floating element will not be affected.
  4. If the image floated to the right, the texts flow around it, to the left and if the image floated to the left, the text flows around it, to the right.

CSS Float Properties

Property Description Values
clear The clear property is used to avoid elements after the floating elements which flow around it. left, right, both, none, inherit
float It specifies whether the box should float or not. left, right, none, inherit

CSS Float Property Values

Value Description
none It specifies that the element is not floated, and will be displayed just where it occurs in the text. this is a default value.
left It is used to float the element to the left.
right It is used to float the element to the right.
initial It sets the property to its initial value.
inherit It is used to inherit this property from its parent element.

CSS Float Property Example

Let’s see a simple example to understand the CSS float property.

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style>
  5. img {
  6.     float: right;
  7. }
  8. </style>
  9. </head>
  10. <body>
  11. <p>The following paragraph contains an image with style
  12. <b>float:right</b>. The result is that the image will float to the right in the paragraph.</p>
  13. <img src=“good-morning.jpg” alt=“Good Morning Friends”/>
  14. This is some text. This is some text. This is some text.
  15. This is some text. This is some text. This is some text.
  16. This is some text. This is some text. This is some text.
  17. This is some text. This is some text. This is some text.
  18. This is some text. This is some text. This is some text.
  19. This is some text. This is some text. This is some text.
  20. This is some text. This is some text. This is some text.
  21. This is some text. This is some text. This is some text.
  22. This is some text. This is some text. This is some text.
  23. This is some text. This is some text. This is some text.
  24. This is some text. This is some text. This is some text.
  25. This is some text. This is some text. This is some text.
  26. This is some text. This is some text. This is some text.
  27. </p>
  28. </body>
  29. </html>