HTML autofocus attribute

autofocus attribute automatically focuses the cursor on the specific input field after the page is loaded.

Example

<form action="files/autofocus.php" method="post">
<p>Email: <input type="email" name="email" autofocus></p>
<p>Password: <input type="password" name="password"></p>
<p><input type="submit" name="login"></p>
</form>
Try </>

autofocus attribute allows the user to start typing directly in the respective input area.

In the above example, the input control of email is focused after the page is loaded.

autofocus attribute value

autofocus is a boolean attribute. A boolean attribute has only two states.

Related Tags

The tags that support autofocus attribute are given below.

<button> tag

The presence of autofocus attribute focuses the button automatically.

Example

<button type="button" autofocus>Submit</button>

Try</>

<input> tag

input control is focused automatically after the page is loaded.

Example

<p> User name: <input type="text" name="uname" placeholder="Name" autofocus></p><p> User name: <input type="password" name="pass" ></p>

Try</>

<textarea> tag

the textarea element also supports autofocus attribute.

Example

<textarea cols="25" rows="9" autofocus>
 It is textarea. It is editable and resizeable by default.But the size can be fixed. The textarea is focused by autofocus attribute.
 </textarea>

Try</>

Related Pages

button defines a button.

input defines an input control.

textarea represents a textarea.



Was this article helpful?

 

Email:

Message:

Get the newsletter