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 right Property
- HTML | DOM Style top Property
- HTML | DOM Style flexWrap Property
- HTML | DOM Style listStyleImage Property
- HTML | DOM Style marginLeft Property
- HTML | DOM Style flexGrow Property
- HTML | DOM Style fontSize Property
- HTML | DOM Style borderTopLeftRadius Property
- HTML | DOM Style verticalAlign Property
- HTML | DOM Style left Property
- HTML | DOM Style captionSide Property
- HTML | DOM Style letterSpacing Property
- HTML | DOM Style textDecorationLine Property
- HTML | DOM Style borderStyle Property
- HTML | DOM Style transitionDuration 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.



