The autofocus attribute is a boolean attribute. When present, it specifies that an <input> element should automatically get focus when the page loads. In other words, the cursor will be sitting in the autofocused input box, when the webpage loads.
HTML file: | Displayed by browser: |
---|---|
<form action="http://www.w3schools.com/html/action_page.php">
First name: <input type="text" name="fname" autofocus> <br /> <br />Last name: <input type="text" name="lname"> <br /> <br /><input type="submit"> </form> |
This should work in all the major browsers but it might not work with Internet Explorer 9 or earlier.