HTML autofocus Attribute

❮ HTML Attributes


<button type="button" autofocus>Click Me!</button>


This is Boolean attribute is used for autofocus when the page loads.

Standard Syntax

HTML: <element autofocus>
XHTML: <element autofocus="autofocus">

Browser Support


Applies to:

The autofocus attribute can be used on the following element:

Element Attribute
<button> autofocus
<input> autofocus
<select> autofocus
<textarea> autofocus

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>

<textarea> Tag Example

<form action="action.php">
	<label for="demo">textarea demo:</label>
	<textarea autofocus id="demo" name="textareaText">
Hello world!
	<input type="submit" value="Submit">
❮ HTML Attributes