W3Schools.com

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.


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 type="text/javascript">
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
WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$7.95/mo SEO Hosting
Premium Website Design
WEB BUILDING
XML Editor - Free Trial!
FREE Website BUILDER
Free Website Templates Free CSS Templates
Make Your Own Website
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE