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

HTML Reference Manual

HTML Tag Directory

HTML: <button> autofocus attribute

The autofocus attribute is a boolean attribute. If present, it specifies that the button should automatically receive focus when the page loads.

 HTML <button> tag

Online Example

Button using autofocus attribute:

<!DOCTYPE html>
<html>
<head>
<title>HTML:<button> autofocus attribute - 基础教程网 oldtoolbag.com</title>
<body>
<button type="button" autofocus onclick="alert('Hello world!39;) Click Me!/button>
</body>
</html>
Test to see ‹/›

Browser Compatibility

IEFirefoxOperaChromeSafari

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

Note: Internet Explorer 9 and earlier IE versions do not support the autofocus attribute.

Definition and Usage

The autofocus attribute is a boolean (boolean) attribute.

The autofocus attribute specifies that the button should automatically gain focus when the page is loaded.

HTML 4.01 and HTML5and

The autofocus attribute is a difference between HTML5new attributes in the <button> tag.

Differences between HTML and XHTML

In XHTML, attribute abbreviations are not allowed, the autofocus attribute must be defined as <button autofocus="autofocus">.

Syntax

<button type="button" autofocus>

 HTML <button> tag