i

Learn HTML and CSS in 10 Days

Adding Audio

HTML5 offers us with the ability to add up audio files with the help of element. Just like the element, the element also comes with an src attribute to provide the source of the desired audio to be loaded in the webpage.

Audio attributes

Multiple other attributes can follow the src attribute in the

element. Some of the most popular ones are controls, preload, autoplay, and preload.

Here the controls, loop, and autoplay attributes are known as Boolean attributes. Thus as they are Boolean attributes, they do not need a stated value.

The autoplay Boolean attribute automatically plays the audio file whenever the web page gets loaded. The use of controls Boolean attribute is to show up default audio control provided by the browser. The preload Boolean attribute distinguishes what, assuming any, data about the audio record ought to be stacked before the clip is played. It takes in 3 values: auto, none, and metadata. The auto value will preload all related info regarding the audio file. The none value will not preload any info about the audio file. The metadata lies in between the auto and none values; it preloads any available info about an audio file.

Audio Fallbacks and Multiple Sources

Presently, the browsers offer multiple audio file formats, three most of the most used ones are mp3, ogg, and wav.

At first, we need to remove the attribute of src from theelement. Instead of that, we are going to use the element with the src attribute, enclosed inside the

element. We will be using the 'type' attribute to help your browser to know which audio types are present.