HTML <button> Tag with the 'autofocus' Attribute

<button autofocus>

Here, we add the autofocus attribute to a button control.

About the autofocus Attribute

The autofocus attribute automatically gives focus to the control when the page loads. This allows the user to start using the control without having to select it first. There must not be more than one element in the document with the autofocus attribute specified.

The autofocus attribute is a boolean attribute. Therefore, if the attribute is present, its value must either be the empty string or a value that is an ASCII case-insensitive match for the attribute's canonical name, with no leading or trailing whitespace (i.e. either autofocus or autofocus="autofocus").

Possible values:

  • [Empty string]
  • autofocus

About the <button> Element

The <button> element creates a button control in an HTML document.

Any contents of the <button> element appears on the button.

The <button> element can be associated with a form or stand alone by itself (in such case it could have JavaScript attached via the onclick attribute) to make the button actually do something.