Open In App
Related Articles

HTML | DOM Style cssFloat Property

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

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:

  • It returns the cssFloat property.
object.style.cssFloat
  • It is used to set the cssFloat property.
object.style.cssFloat = "left|right|none|initial|inherit"

Return Values: It returns a string value that represents the horizontal alignment of an element

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: 

html

<!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: 

html

<!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 1 and above
  • Edge 12 and above
  • Internet Explorer 4 and above
  • Mozilla Firefox 1 and above
  • Safari 1 and above
  • Opera 7 and above


Last Updated : 07 Jun, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads