HTML <input> autofocus attribute

Definition and Usage

autofocus The attribute specifies that the input element should automatically gain focus when the page is loaded.

autofocus The attribute is a boolean attribute.

If this property is set, it specifies that the <input> element should automatically gain focus when the page is loaded.

Example

Make the "First name" input field automatically focused when the page loads:

<form action="/action_page.php">
  <label for="fname">Name:</label>
  <input type="text" id="fname" name="fname" autofocus><br><br>
  <label for="lname">Surname:</label>
  <input type="text" id="lname" name="lname"><br><br>
  <input type="submit">
</form>

Try It Yourself

Syntax

<input autofocus>

Browser Support

The numbers in the table indicate the first browser version that fully supports this property.

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
5.0 11.0 4.0 5.0 9.6

Note:autofocus Attributes are new properties in HTML5.