English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

HTML Tag大全

HTML: <input> autofocus attribute

The autofocus attribute is a boolean attribute. The autofocus attribute specifies that the <input> element should automatically receive focus when the page loads.

 HTML <input> tag

Online Example

When the page loads, automatically focus on the name="fname" field:

<!DOCTYPE html>
<html>
<head>
<title>HTML: <input> autofocus attribute - 基础教程网(oldtoolbag.com)</title>
<body>
<form action="action_page.php">
  First name: <input type="text" name="fname" autofocus><br>
  Last name: <input type="text" name="lname"><br>
  <input type="submit">
</form>
</body>
</html>
Test to see ‹/›

Browser Compatibility

IEFirefoxOperaChromeSafari

Internet Explorer 10Firefox, Opera, Chrome and Safari support the autofocus attribute.

Note:Internet Explorer 9 and earlier versions do not support the autofocus attribute of the <input> tag.

Definition and Usage

The autofocus attribute is a boolean attribute.

The autofocus attribute specifies that the <input> element should automatically receive focus when the page is loaded.

HTML 4.01 with HTML5differences

The autofocus attribute is an HTML5 new attributes.

Differences between HTML and XHTML

In XHTML, attribute shorthand is prohibited, the autofocus attribute must be defined as <input autofocus="autofocus" />.

Syntax

<input autofocus>

 HTML <input> tag