- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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
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