![]() |
Definition and UsageThe When present, it specifies that the element should automatically get focus when the page loads. Applies toThe
Browser SupportThe |
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The button autofocus attribute</h1>
<button type="button" autofocus onclick="alert('Hello world!')">Click Me!</button>
</body>
</html>
Let the "First name" input field automatically get focus when the page loads.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The autofocus attribute</h1>
<form action="/action_page.php">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname" autofocus><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<input type="submit">
</form>
</body>
</html>
The textarea autofocus attribute.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The textarea autofocus attribute</h1>
<textarea rows="4" cols="50" autofocus>
At w3schools.com you will learn how to make a website. We offer free tutorials in all web development technologies.
</textarea>
</body>
</html>
html autofocus attribute |
How to add A button with autofocus in HTML Page | HTML Attribute |
How to add The autofocus attribute | HTML Attribute |
How to add A text area with autofocus | HTML Attribute |
Read Full: | HTML Attribute |
Type: | Develop |
Category: | Web Tutorial |
Sub Category: | HTML Attribute |
Uploaded by: | Admin |
Views: | 91 |
Reffered: https://www.w3schools.com/tags/att_autofocus.asp