Zum Inhalt springen

HTML autoplay-Attribut

Das HTML autoplay-Attribut ist ein boolesches Attribut und gibt an, dass Audio oder Video so schnell wie möglich automatisch abgespielt werden sollen.

Sie können dieses Attribut für die folgenden Elemente verwenden: <audio> und <video>.

Syntax

html
<tag autoplay>&lt;/tag&gt;

Hinweis: Moderne Browser beschränken die Autoplay-Funktion für Medien mit Audiospuren. Damit Autoplay funktioniert, müssen Sie dem Element auch das Attribut muted hinzufügen.

Beispiel für das HTML autoplay-Attribut im <audio>-Element:

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>
    <audio controls autoplay>
      <source src="https://de.w3docs.com/build/audios/jingle_bells.ogg" type="audio/ogg" />
      <source src="https://de.w3docs.com/build/audios/audio.mp3" type="audio/mpeg" />
    </audio>
    <p>Click the play button</p>
  </body>
</html>

Beispiel für das HTML autoplay-Attribut im <video>-Element:

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>
    <video width="320" height="240" controls autoplay muted>
      <source src="http://techslides.com/demos/sample-videos/small.ogv" type="video/ogg" />
      <source src="https://de.w3docs.com/build/videos/arcnet.io(7-sec).mp4" type="video/mp4" />
    </video>
    <p>Some information about video</p>
  </body>
</html>

Practice

Wie wird das 'autoplay'-Attribut in HTML korrekt verwendet?

Finden Sie das nützlich?

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