Zum Inhalt springen

HTML autofocus-Attribut

Das HTML autofocus-Attribut ist ein boolesches Attribut, das festlegt, dass ein Element beim Laden der Seite automatisch den Fokus erhalten muss.

Das autofocus-Attribut ist neu in HTML5.

Syntax

Syntax des HTML autofocus-Attributs

html
<input autofocus>
Gilt fürHTML-Elemente <button>, <input>, <select> und <textarea>.

Beispiel für das HTML autofocus-Attribut:

Beispiel für das HTML autofocus-Attribut

html
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Title of the document.</title>
  </head>
  <body>
    <h1>Example of the HTML "autofocus" attribute.</h1>
    <form action="#">
      Name: <input type="text" name="fname" autofocus /><br />
      Surname: <input type="text" name="lname" /><br />
      <input type="submit" />
    </form>
  </body>
</html>

Hinweis: Einige mobile Browser ignorieren das autofocus-Attribut möglicherweise, um zu verhindern, dass die Seite automatisch scrollt oder die virtuelle Tastatur unerwartet geöffnet wird.

Practice

Was ist laut der angegebenen URL über das HTML autofocus-Attribut wahr?

Finden Sie das nützlich?

Dual-run-Vorschau — vergleichen Sie mit den Symfony-Routen live.