Dofactory.com
Dofactory.com
Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

HTML <select> autofocus Attribute

The autofocus attribute on a <select> tag specifies that the select element immediately has focus upon page load.

Focus means that keyboard input is directed to that control.

Example

#

A <select> element with autofocus enabled. After page load, this control has focus. To confirm, press the spacebar and/or the arrow keys to scroll through the dropdown options.


<form action="/tutorial/action.html">
  <select name="size" autofocus>
    <option value="">-- Select Size --</option>
    <option value="small"> Small </option>
    <option value="medium"> Medium </option>
    <option value="large"> Large </option>
  </select> <br/>
  
  <button type="submit">Submit</button>
</form>

Using autofocus

The autofocus attribute sets focus to the select element once the page is loaded.

Only a single element on a page can have focus.

Therefore, only one element on a page can have the autofocus attribute.


Syntax

<select autofocus>

Browser support

Here is when autofocus support started for each browser:

Chrome
1.0 Sep 2008
Firefox
Not Supported
IE/Edge
10.0 Sep 2012
Opera
1.0 Jan 2006
Safari
1.0 Jan 2003

You may also like

 Back to <select>

Last updated on Sep 30, 2023

Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

Guides