HTML Attributes

HTML autofocus Attribute

The autofocus attribute makes a form control receive focus automatically when the page loads.


The autofocus Attribute

autofocus is a boolean global attribute most useful on form controls such as <input>, <textarea>, <select> and <button>. When present, the element automatically receives keyboard focus as soon as the page finishes loading, so the user can start typing without clicking first.

Syntax

ℹ️

Syntax: <input autofocus>. Being boolean, it takes no value. Only one element per page should have autofocus; if several do, the browser focuses the first.

Focus the search field on page load
<form action="/search">
  <input type="search" name="q" placeholder="Search internships" autofocus>
</form>
ValueDescription
autofocusPresent: the element is focused automatically on page load
(omitted)Absent: no automatic focus is applied
⚠️

Use autofocus carefully. Automatically moving focus can disorient screen-reader users and cause the page to scroll unexpectedly on mobile. Avoid it on pages where the main content should be read first.

Ready to use your HTML skills?

Find web development internships and fresher jobs across India.

Browse Web Dev Internships