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:

  • It returns the cssFloat property.
    object.style.cssFloat
  • It is used to set the cssFloat property.
    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:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    Output:
    Before Click on the button:

    After Click on the button:

    Example 2:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    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


    My Personal Notes arrow_drop_up

    Check out this Author's contributed articles.

    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.




    Article Tags :
    Practice Tags :


    Be the First to upvote.


    Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.