title: HTML5 Audio
Before HTML5, audio files required a browser plug-in like Adobe Flash.
The element is used to embed sound content in HTML documents. It may contain one or more audio sources, represented using the src attribute or the source element.
The following code snippet adds an audio file with the filename
tutorial.mp3. The element indicates alternative audio files which the browser may choose. The browser will utilize the first recognized format.
<audio controls> <source src="tutorial.ogg" type="audio/ogg"> <source src="tutorial.mp3" type="audio/mpeg"> Your browser does not support the audio element. </audio>
<audio src="https://s3.amazonaws.com/Codevarsity/simonSound1.mp3" controls loop autoplay> </audio>
controls attribute includes audio controls like play, pause, and volume. If you do not use this attribute, then no controls will be shown.
<source> element enables you to indicate alternative audio files which the browser may choose from. The browser will utilize the first recognized format.
The text between the
</audio> tags may be shown in a browser that does not support the HTML5
The autoplay attribute will automatically play your audio file in the background. It is better practice to let users choose to play audio.
The preload attribute indicates what the browser should do if the player is not set to autoplay.
The loop attribute will play your audio file in a continous loop if mentioned.
Some browsers do not support HTML5. Find out here: https://caniuse.com/#search=audio