HTML Autofocus Attribute
On this page, you can find information about the HTML autofocus attribute, see its usage, the elements that it applies to,as well as try different examples.
The HTML autofocus attribute is a boolean attribute, which defines that an element must automatically get focus when the page loads.
The autofocus attribute is new in HTML5.
Syntax
Syntax of HTML Autofocus Attribute
<input autofocus>| Applies to | HTML <button>, <input>, <select>, and <textarea> elements. |
|---|
Example of the HTML autofocus attribute:
Example of HTML Autofocus Attribute
<!DOCTYPE html>
<html lang="en">
<head>
<title>Title of the document.</title>
</head>
<body>
<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" />
</form>
</body>
</html>Note: Some mobile browsers may ignore the autofocus attribute to prevent the page from automatically scrolling or opening the virtual keyboard unexpectedly.
Practice
Practice
What is true about the HTML autofocus attribute according to the specified URL?