HTML autofocus attribute
HTML autofocus attribute automatically focuses the cursor on the specific input field after the page is loaded.
<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></>
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.
Attribute valuesAll possible values of autofocus attribute
autofocus is a boolean attribute. A boolean attribute has only two states.
Related TagsThe tags that support autofocus attribute
The presence of autofocus attribute focuses the button automatically.
<button type="button" autofocus>Submit</button>Try</>
input control is focused automatically after the page is loaded.
<p> User name: <input type="text" name="uname" placeholder="Name" autofocus></p><p> User name: <input type="password" name="pass" ></p>Try</>
the textarea element also supports autofocus attribute.
<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</>
Was this article helpful?