 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML <button> autofocus Attribute
The autofocus attribute of the <button> element is used to set focus to the button whenever page loads.
Following is the syntax −
<button type="button" autofocus>
Above, we have set autofocus to a button. Let us now see an example to implement the autofocus attribute of the <button> element −
Example
<!DOCTYPE html> <html> <body> <h2>Demo Heading</h2> <p>This is a demo line.</p> <button type="button" autofocus >Demo</button> </body> </html>
Output
This will produce the following output displaying the focus is on button 1 −

In the above example, we have set the autofocus attribute for the button element −
<button type="button" autofocus > Demo </button>
Now, when the page loads, the focus would be on the button itself and the same would appear to the visitor on the web page.
Advertisements
 