Horje

How to add HTML <audio> autoplay Attribute

An audio file that will automatically start playing:

Definition and Usage

The autoplay attribute is a boolean attribute.

When present, the audio will automatically start playing as soon as it can do so without stopping.

Note: Chromium browsers do not allow autoplay in most cases. However, muted autoplay is always allowed.

Add muted after autoplay to let your audio file start playing automatically (but muted).

Browser Support

The numbers in the table specify the first browser version that fully supports the attribute.

Syntax

<audio autoplay>

index.html
Example: HTML
<!DOCTYPE html>
<html>
<body>
<h1>The audio autoplay attribute</h1>
<p>Click on the play button to play a sound:</p>
<audio controls autoplay> <source src="https://www.w3schools.com/tags/horse.ogg" type="audio/ogg"> <source src="https://www.w3schools.com/tags/horse.ogg" type="audio/mpeg"> Your browser does not support the audio element.
</audio>
</body>
</html>

Output should be:

How to add HTML <audio> autoplay Attribute




Type :
html
Category :
Web Tutorial
Sub Category :
HTML Tag
Uploaded by :
Admin