HTML Autofocus Attribute

The HTML autofocus attribute is a boolean attribute, which defines that an <input> element must automatically get focus when the page loads.

The autofocus attribute is new in HTML5.


<input autofocus>
Applies to HTML <input> element.

Example of the HTML autofocus attribute:

<!DOCTYPE html>
    <title>Title of the document.</title>
    <h1>Example of the HTML "autofocus" attribute.</h1>
    <form action="#">
      Name: <input type="text" name="fname" autofocus><br>
      Surname: <input type="text" name="lname"><br>
      <input type="submit">

Practice Your Knowledge

What is true about the HTML autofocus attribute according to the specified URL?

Quiz Time: Test Your Skills!

Ready to challenge what you've learned? Dive into our interactive quizzes for a deeper understanding and a fun way to reinforce your knowledge.

Do you find this helpful?