HTML | DOM Style cssFloat Property
The style cssFloat property in HTML DOM is used to set or returns the horizontal alignment of element. This property allows an element to float right or left side of the parent body with rest of the elements wrapped around it.
Syntax:
object.style.cssFloat
object.style.cssFloat = "left|right|none|initial|inherit"
Property Values:
- None: It is the default value. This value does not create float.
- Left: Floats the element to the left side of the parent body/container.
- Right: Floats the element to the right side of the parent body/container.
- Initial: Sets the element to its initial position.
- Inherit: The Element inherits its floating property from parent element.
Example 1:
<!DOCTYPE html> <html> <head> <title> HTML DOM Style cssFloat Property </title> </head> <body> <h1 id = "GFG">GeeksForGeeks</h1> <h2>HTML | DOM cssFloat property</h2> <button onclick = "RightFloat()"> Float right </button> <!-- script to set float of element --> <script> function RightFloat() { document.getElementById("GFG").style.cssFloat = "right"; } </script> </body> </html> |
Output:
Before Click on the button:

After Click on the button:

Example 2:
<!DOCTYPE html> <html> <head> <title> HTML DOM Style cssFloat Property </title> </head> <body> <h1 id = "GFG">GeeksForGeeks</h1> <h2>HTML | DOM cssFloat property</h2> <button onclick = "RightFloat()"> Float Right </button> <button onclick = "LeftFloat()"> Float Left </button> <!-- script to set float of element --> <script> function RightFloat() { document.getElementById("GFG").style.cssFloat = "right"; } function LeftFloat() { document.getElementById("GFG").style.cssFloat = "left"; } </script> </body> </html> |
Output:
Before Click on the button:

After Click on the float left button:

After Click on the float right button:

Supported Browsers: The browser supported by Style cssFloat property are listed below:
- Google Chrome
- Internet Explorer
- Mozilla Firefox
- Safari
- Opera
Recommended Posts:
- HTML | DOM Style top Property
- HTML | DOM Style right Property
- HTML | DOM Style overflowY Property
- HTML | DOM Style margin Property
- HTML | DOM Style marginBottom Property
- HTML | DOM Style border Property
- HTML | DOM Style emptyCells Property
- HTML | DOM Style outlineColor Property
- HTML | DOM Style columnRule Property
- HTML | DOM Style borderRadius Property
- HTML | DOM Style flexDirection Property
- HTML | DOM Style perspective Property
- HTML | DOM Style background Property
- HTML | DOM Style textTransform Property
- HTML | DOM Style wordWrap Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



