- 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 of the <input> element is used to specify which of the <input> would get focus when the web page loads. This attribute introduced in HTML5.
Following is the syntax −
<input autofocus>
Let us now see an example to implement the autofocus attribute of the <input> element −
Example
<!DOCTYPE html> <html> <body> <h2>Log in to your account</h2> <form action="" method="get"> Id: <input type="text" name="id"><br> Password: <input type="password" name="pwd"><br> DOB: <input type="date" name="dob" autofocus><br> <button type="submit" value="Submit">Submit</button> </form> </body> </html>
Output
In the above example, we have created a form −
<form action="" method="get"> Id: <input type="text" name="id"><br> Password: <input type="password" name="pwd"><br> DOB: <input type="date" name="dob" autofocus><br> <button type="submit" value="Submit">Submit</button> </form>
We have set autofocus to the third input as shown below i.e. DOB, therefore the cursor is visible there itself −
DOB: <input type="date" name="dob" autofocus><br>
Advertisements