HTML | DOM Button autofocus Property

The Button autofocus property in HTML DOM is used to set or return whether the button should get focus when the page loads. This property is used to reflect the HTML autofocus attribute.


  • It is used to return the autofocus property.
  • It is used to set the autofocus property.
    buttonObject.autofocus = true|false
  • Property Values:

    • true: It defines the button element get focused.
    • false: It is the default value. It defines the Button Element does not get focus.

    Return Value: It returns a boolean value which represents the Button element get autofocus otherwise return False.

    Example: This example returns the button autofocus value.





    <!DOCTYPE html> 
            HTML DOM button autofocus Property 
    <body style="text-align:center"
        <h1 style="color: green;"
            HTML DOM button autofocus Property
        <!-- Assign id to the Button. -->
        <button id="GFG" autofocus>
            Click on "button" Button to return
            button autofocus Property.
        <button onclick="Geeks()">
        <p id="sudo"></p
        <!-- Script to return button autofocus value -->
            function Geeks() { 
                // Return Boolean value to represent Button. 
                var x = document.getElementById("GFG").autofocus; 
                document.getElementById("sudo").innerHTML = x; 



    Before Click on the Button:

    After Click on the Button:

    Supported Browsers: The browser supported by DOM Button autofocus property are listed below:

    • Google Chrome
    • Internet Explorer 10.0
    • Firefox
    • Opera
    • Safari

    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 or mail your article to 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 to report any issue with the above content.