HTML <input> Tag with the 'autofocus' Attribute

Above is an example of adding the autofocus attribute to an input control. The autofocus attribute allows the user to start typing without having to select a control first.

In this example, we add the autofocus attribute to the second <input> element (out of three). This results in the second input control being in focus when the page loads. If the user starts typing without selecting any controls, text will be entered into the second 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").