Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

HTML | DOM Select autofocus Property

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The Select autofocus property in HTML DOM is used to set or return whether a drop-down list should automatically get focused when the page loads, or not
The property returns true if the drop-down list automatically gets focus otherwise, it returns false. 
The Select autofocus property reflects the HTML autofocus attribute.
Syntax for returning the autofocus property 


Syntax for setting the autofocus property 

selectObject.autofocus = true|false

Property Values 

  • true :The drop-down list get autofocus.
  • false : It has a default value. The drop-down list does not get focus.

Return Value: It returns a Boolean value which represents that the dropdown list get focus or not. 

Below program illustrates the Select autofocus property :
Example-1: Finding out if a drop-down list automatically gets focus upon page load.


<!DOCTYPE html>
      Select Autofocus Property in HTML
        h1 {
            color: green;
        h2 {
            font-family: Impact;
        body {
            text-align: center;
      Select Autofocus Property
  Select your preferred course from the drop-down list:
    <select id="Courses" autofocus>
        <option value="C++">c++</option>
        <option value="Placement">Placement</option>
        <option value="Java">Java</option>
        <option value="Python">Python</option>
      To find out if the drop-down list
      automatically gets focused upon page load
      or not, double-click the "Check" button.
    <button onclick="My_list()">Check</button>
    <p id="test"></p>
        function My_list() {
            var d =
            document.getElementById("test").innerHTML = d;

Before clicking the button: 

After clicking the button: 

Supported Browsers: The browser supported by DOM Select autofocus Property are listed below: 

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


My Personal Notes arrow_drop_up
Last Updated : 17 Nov, 2021
Like Article
Save Article
Similar Reads
Related Tutorials