English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSS reference manual

CSS @rule (RULES)

CSS attribute大全

CSS float Attribute Usage and Examples

The CSS float attribute specifies whether a box should float to the left, right, or not float at all.

The following table provides usage instructions and version history of this attribute, as well as the syntax of using this attribute in JavaScript scripts.

Default Value:none
Applicable To:All Elements
Inheritance:None
Animatable:No.Please see Animation Attributes.
Version:CSS 1,2,3
JavaScript Syntax:object.style.cssFloat="right"

Syntax of float

The syntax of this attribute is as follows:

float: left | right | none | initial | inherit

The following examples demonstrate how to use the float attribute.

  p.red {
   float: left;
  }
  p.green {
   float: right;
  }
Test to see‹/›

Attribute Value

The following table describes the values of this attribute.

ValueDescription
leftThe element floats to the left. The content starts from the top and flows to the right side of the box.
rightSimilar to left, the difference is that the box floats on the right, and the content starts from the left side of the box, starting from the top.
noneThis box is not floated. This is the default value.
initialSet this attribute to its default value.
inheritIf specified, the associated elements adopt the float attribute value of their parent element.

Browser Compatibility

Browser Compatibility of float Attribute, the numbers in the following table represent the minimum version number of browsers that support this attribute; all mainstream browsers support this attribute.

  • Firefox 1+

  • Google Chrome1+

  • Internet Explorer 4+

  • Apple Safari 1+

  • Opera 7+

Further Reading

Please refer to the following tutorials:CSS Float,CSS Alignment.

Position-related Attributes:position,top,right,bottom,left,display,clear.