HTML5: How to specify that an input element should automatically get focus when the page loads?
Solution :
HTML Code:
Explanation:
- This HTML code demonstrates how to create a form with an input field that automatically receives focus when the page loads.
- The form is configured with the method attribute set to "POST" and the action attribute set to the URL where the form data will be submitted.
- Within the form, there are text input fields for entering the first name, last name, and address.
- The input field for the first name has the autofocus attribute, which automatically gives it focus when the page loads.
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.