HTML <input> autofocus Attribute

The autofocus attribute on a <input> tag specifies that the input element receives focus when the page has loaded.

Example

#

An autofocus attribute on a <input> element.
The control has focus and currently displays the blinking text entry cursor.



<form action="/tutorial/action.html">
  <input autofocus type="text" placeholder="Enter your name"
         name="name" autofocus><br /><br />

  <input type="submit">
</form>

Using autofocus

The autofocus attribute specifies that the input element receives focus on page load.

Only one element on a page can have the autofocus attribute.


Syntax

<input autofocus>

Browser support

Here is when autofocus support started for each browser:

Chrome
5.0 May 2010
Firefox
4.0 Mar 2011
IE/Edge
11.0 Oct 2013
Opera
9.6 Oct 2008
Safari
5.0 Jun 2010

You may also like

 Back to <input>
Guides