Search w3schools.com:

SHARE THIS PAGE

Style cssFloat Property

Style Object Reference Style Object

Definition and Usage

The cssFloat property sets or returns the horizontal alignment of an object.

Syntax

Set the cssFloat property:

Object.style.cssFloat="left|right|none|inherit"

Return the cssFloat property:

Object.style.cssFloat

Value Description
left The object/element will float to the left in the parent element
right The object/element will float to the right in the parent element
none The object/element is not floated. This is default
inherit The value of the cssFloat property is inherited from the parent element


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The cssFloat property is supported in all major browsers.

Note: The value "inherit" is not supported in IE7 and earlier. IE8 requires a !DOCTYPE. IE9 supports "inherit".


Tips and Notes

Note: If there is too little space on a line for the floating element, it will jump down to the next line that has enough space.


Example

Example

Let an image float to the left/right of the text, when clicking on two buttons:

<html>
<head>
<script>
function floatRight()
{
document.getElementById("img1").style.cssFloat="right";
}
function floatLeft()
{
document.getElementById("img1").style.cssFloat="left";
}
</script>
</head>
<body>

<img id="img1" src="w3javascript.gif" width="100" height="132">

<p>This is a paragraph.</p>
<p>This is another paragraph.</p>

<input type="button" onclick="floatRight()" value="Float right">
<input type="button" onclick="floatLeft()" value="Float left">

</body>
</html>

Try it yourself »


Style Object Reference Style Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]