float property
Sets or retrieves on which side of the object the text will flow.
![]() |
Syntax
float: left | right | none
Property values
none-
Default. Object displays where it appears in the text.
left-
Text flows to the right of the object.
right-
Text flows to the left of the object.
CSS information
| Applies To | All elements |
|---|---|
| Media | visual |
| Inherited | no |
| Initial Value | none |
Standards information
- CSS 2.1, Section 5.5.25
Remarks
With a value of left or right, the object is treated as block-level—that is, the display property is ignored. For example, floating paragraphs allow the paragraphs to appear side-by-side.
Objects following a floating object move in relation to the position of the floating object.
The floating object is moved left or right until it reaches the border, padding, or margin of another block-level object.
The div and span objects must have a width set for the float attribute to render. In Microsoft Internet Explorer 5, div and span objects are assigned a width by default and will render if a width is not specified.
Examples
This example shows how the float property affects the flow of the text. In the three div elements below, the blue square image floats to the left and right of the text. The third div element show the image and text with no float value applied.
<div> <img class="left" src="square.png" alt="Blue square"/> <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p> </div> <div> <img class="right" src="square.png" alt="Blue square"/> <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p> </div> <div> <img src="square.png" alt="Blue square"/> <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p> </div>
Below is the CSS with values for margin and float applied.
body {
width: 500px;
}
.left {
float: left;
margin: 5px;
}
.right {
float: right;
margin: 5px;
}
You can see the result below. The first div sets float to left, the second div sets float to right, and the float property is not used in the third div.

This example uses inline scripting and the floatproperty to swap images when the mouse moves over the button.
Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/styleFloat.htm
<img id="oSphere" scr="sphere.jpeg" style="float:left"> <img id="oCone" src="cone.jpeg" style="float:right"> : <button onmouseover="oSphere.style.styleFloat='right'; oCone.style.styleFloat='left'" onmouseout="oSphere.style.styleFloat='left'; oCone.style.styleFloat='right'"> Flip-flop images. </button>
See also
