HTML autofocus Attribute
Example
<button type="button" autofocus>Click Me!</button>
Meaning
This is Boolean attribute is used for autofocus when the page loads.
Standard Syntax
HTML: <element autofocus>
XHTML: <element autofocus="autofocus">
Browser Support
Status
Applies to:
The autofocus attribute can be used on the following element:
Attribute Values
Value | Description |
---|---|
autofocus | This is a boolean attribute, the presence of a boolean attribute on an element represents the true value, and the absence of the attribute represents the false value. |
More Examples
<input> tag Example
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname" autofocus><br>
<input type="submit">
<select> Tag Example
<label for="lang">Choose your option:</label>
<select name="language" id="lang" autofocus>
<option value="HTML">HTML</option>
<option value="CSS">CSS</option>
<option value="JavaScript">JavaScript</option>
</select>
<textarea> Tag Example
<form action="action.php">
<label for="demo">textarea demo:</label>
<textarea autofocus id="demo" name="textareaText">
Hello world!
</textarea>
<br><br>
<input type="submit" value="Submit">
</form>