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 |
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 attribute affects the flow of the text. The sphere image floats to the left of the text, and the cone floats to the right.
Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/float_h.htm
<img src="sphere.jpg" style="float:left"> <img src="cone.jpg" style="float:right">
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.
</butotn>
See also
Send comments about this topic to Microsoft
Build date: 11/29/2012

