Audio tag in HTML
- 24-07-2022
- Trung Minh
- 0 Comments
The <audio> tag defines it as an audio file, such as a music file or another audio stream.
There are 3 formats supported by the <audio> tag:
- MP3
- WAV
- Ogg
How to use the <audio> . tag
Example : Use <audio> tag to insert audio into web page, prepare music.mp3 file at the same level as html file's directory..
<!DOCTYPE html> <html> <head> <title>Học lập trình miễn phí tại web888.vn</title> <meta charset="utf-8"> </head> <body> <h1>Học lập trình miễn phí tại web888.vn</h1> <audio> <source src="music.mp3" type="audio/mpeg"> </audio> </body> </html>
Attribute of <audio> . tag
- autoplay – the file will automatically run when it has finished loading.
- controls – specifies the audio controls that should be displayed.
- loop – determines whether to play back the file or not.
- muted – mutes the file's sound.
- src – path to the audio file.
Browser support
- Chrome 4.0
- Firefox 3.5
- IE 9.0
- Safari 4.0
- Opera 10.5