Dofactory.com
Dofactory.com
Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

HTML <button> autofocus Attribute

The autofocus attribute on a <button> tag specifies that the button has focus once the page is loaded..

Focus means that keyboard input is directed to that control.

Example

#

A <button> with autofocus enabled. The button currently has focus. Press the space bar or the enter key to trigger the button click event.

<button autofocus 
        onclick="alert('Yes. I have autofocus.')">Confirm</button>

Using autofocus

The autofocus attribute sets focus to the button upon page load.

Only a single element on a page can have focus.

Therefore, only one element on a page can have the autofocus attribute.


Syntax

<button autofocus>

Browser support

Here is when autofocus support started for each browser:

Chrome
5.0 May 2010
Firefox
4.0 Mar 2011
IE/Edge
10.0 Sep 2012
Opera
9.6 Oct 2008
Safari
5.0 Jun 2010

You may also like

 Back to <button>

Last updated on Sep 30, 2023

Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

Guides