<audio>
HTML <audio> Tag
Instance
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> </head> <body> <audio controls> <source src="horse.ogg" > <source src="horse.mp3" > 您的浏览器不支持 audio 元素。 </audio> </body> </html>
Run Example»
Click the "Run Instance" button to view the online instance
Browser support
IE 9+, Firefox, Opera, Both Chrome and Safari support the <audio> tag.
Note: IE 8 or earlier versions of IE browsers do not support the <audio> tag.
Tag definition and usage instructions
<audio> tag defines sound, such as music or other audio streams.
Currently, the <audio> element supports three file formats: MP3, Wav, and Ogg.
Browser | MP3 | Wav | Ogg |
---|---|---|---|
Internet Explorer | YES | NO | NO |
Chrome | YES | YES | YES |
Firefox | YES | YES | YES |
Safari | YES | YES | NO |
YES | YES | YES |
Differences between HTML 4.01 and HTML5<audio> tag is New tags for HTML5.
Tips and Notes
Tips: You can place text content between <audio> and </audio>, and the text information will be Displayed in browsers that do not support the <audio> tag.
Attribute
New: New attribute in HTML5.
Value | Description | |
---|---|---|
New | autoplayIf this attribute appears, the audio will be played as soon as it is ready. | |
New | controlsIf present, displays audio controls (such as play/pause buttons) to the user ). | |
New | loopIf this attribute is present, playback will restart whenever the audio ends. | |
New | mutedIf this attribute is present, the audio output is muted. | |
New | auto
metadata none | Specifies whether and how audio is loaded by default when the web page is loaded. |
New | URL | Specifies the URL of the audio file.