With HTML5, you no longer need plugins to have and play audio files on your webpage.
tag is used for creating audio elements.
<audio controls><source src='my_audio_file_path.mp3' type='audio/mpeg'/>Audio file not supported.</audio>
<audio controls><source src='audio.mp3' type='audio/mpeg'/>Audio file not supported.</audio>
Copy PRACTICE IT
tag defines the audio element. The controls
keyword contained in the opening tag helps your audio element have basic options or controls such as play, pause, volume and etcetera
, which may vary from browser to browser.
Inside the audio
element is also the <source>
tag which is generally used in defining media files for media elements. There is also a text (Audio file not supported.
), which is a text to display when a browser doesn't support the audio element.
element have an src
attribute to specify the path to the audio file and a type
attribute to specify the media type of the audio file.
You can have as many <source>
elements in the <audio>
element, which represents different media format of an audio file from which a browser can select from. The browser will usually select the first <source>
element with an audio type it supports.
<source src='myaudio.mp3' type='audio/mpeg'/>
<source src='myaudio.wav' type='audio/wav'/>
Audio file not supported.</audio>
- The <audio> tag is used in creating audio elements in a webpage.
- You can specify the keyword controls to let your audio element have basic controls such as play, pause and etcetera according to each browser.
- Inside an audio element is one or more <source> elements and finally a text to display when a browser doesn't support an audio element.
- The <source> tag allows us to specify one or more audios in different media format or type so that a browser can choose which to play.
- The browser will usually choose the first source element with a media type it supports.