HTML5: How to specify that the drop-down list should automatically get focus when the page loads?
Solution:
HTML Code:
Explanation:
- This HTML code defines a webpage with a form containing a dropdown menu.
- The form allows users to select one or more sections.
- The dropdown menu has two groups: "Server_side" and "Client_side".
- Each group contains multiple options.
- The autofocus attribute is added to the >select> tag, indicating that the dropdown menu should automatically receive focus when the page loads. This means that the dropdown will be highlighted or active by default, allowing users to interact with it without having to click on it.
- This enhances user experience by immediately directing attention to the dropdown, especially in cases where user input is expected upon page load.
Live Demo:
See the solution in the browser
Supported browser
![]() |
![]() |
![]() |
![]() |
![]() |
Yes | Yes | Yes | Yes | Yes |
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.