- 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 autofocus Attribute
The autofocus attribute in HTML is used for multiple elements and sets the focus on that particular element when the page loads. The element that constitutes the autofocus attributes are.
<button>, <input>, <select> and <textarea>.
Let us now see an example to implement the autofocus attribute in HTML−
Example
<!DOCTYPE html> <html> <body> <h2>Result</h2> <form action="" accept-charset="ISO-8859-1"> <label for="stinfo">Student:</label> <input type="text" name ="stinfo"><br> <label for="sub">Subject:</label> <input type="text" name ="sub" autofocus><br> <label for="rank">Rank:</label> <input type="number" name ="rank"><br> <label for="marks">Marks:</label> <input type="number" name ="marks"><br><br> <input type="submit"> </form> </body> </html>
Output
This will produce the following output displaying the focus on the 2nd textbox, since we have set autofocus on the same input text −
Advertisements