W3docs

HTML autoplay-Attribut

The HTML autoplay specifies that the audio or video will start playing automatically as soon as possible. See how to use it on the <audio> and <video> elements.

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

<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:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>
    <audio controls autoplay>
      <source src="/build/audios/jingle_bells.ogg" type="audio/ogg" />
      <source src="/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:

<!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="/build/videos/arcnet.io(7-sec).mp4" type="video/mp4" />
    </video>
    <p>Some information about video</p>
  </body>
</html>

Practice

Übung

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