HTML -Autofokus -Attribut
Definition und Verwendung
Das
autofocus
Attribut ist ein boolesches Attribut.
Wenn vorhanden, gibt es an, dass das Element automatisch den Fokus erhalten soll, wenn die Seite geladen wird.
Gilt für
Das
autofocus
Attribut kann für die folgenden Elemente verwendet werden:
Elemente | Attribut |
---|---|
<Schaltfläche> | Autofokus |
<Eingabe> | Autofokus |
<auswählen> | Autofokus |
<Textbereich> | Autofokus |
Beispiele
Schaltflächenbeispiel
Eine Taste mit Autofokus:
<button type="button" autofocus>Click Me!</button>
Eingabebeispiel
Lassen Sie das Eingabefeld "Vorname" automatisch den Fokus erhalten, wenn die Seite geladen wird:
<form action="/action_page.php">
First name: <input type="text" name="fname" autofocus><br>
Last name: <input type="text" name="lname"><br>
<input type="submit">
</form>
Textarea-Beispiel
Ein Textbereich mit Autofokus:
<textarea autofocus>
At w3schools.com you will learn how to make a website. We offer free tutorials in all web development technologies.
</textarea>
Browser-Unterstützung
Das autofocus
Attribut hat die folgende Browserunterstützung für jedes Element:
Element | |||||
---|---|---|---|---|---|
form | 5.0 | 10.0 | 4.0 | 5.0 | 9.6 |
input | 5.0 | 10.0 | 4.0 | 5.0 | 9.6 |
textarea | Yes | 10.0 | 4.0 | Yes | Yes |