Skip to content
Related Articles

Related Articles

HTML | DOM Style cssFloat Property
  • Last Updated : 31 Jan, 2019

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

    full-stack-img

    My Personal Notes arrow_drop_up
    Recommended Articles
    Page :