Posts in current category

HTML5 Audio (Audio)

May 03, 2021 13:05 HTML5

Table of contents

HTML5 Audio

HTML5 provides the standard for playing audio files.

By using the audio feature in HTML5, you can implement the same functionality as flash, i.e. playback, jump, buffering, and so on.

Audio on the Internet

Until now, there was no standard for playing audio on a Web page.

Today, most audio is played through plug-ins such as Flash. However, not all browsers have the same plug-in.

HTML5 sets out the criteria for embedding audio elements on a Web page, i.e., using the element.

Browser support

HTML5 Audio (Audio) HTML5 Audio (Audio) HTML5 Audio (Audio) HTML5 Audio (Audio) HTML5 Audio (Audio)

Internet Explorer 9 Plus, Firefox, Opera, Chrome, and Safari all support the elements.

Note: Internet Explorer 8 and earlier versions of IE do not support the element.

HTML5 Audio - How it works

To play audio in HTML5, you need to use the following code:

<audio controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
您的浏览器不支持 audio 元素。

Try it out . . .

Control property to add playback, pause, and volume controls.

Between the sl;audio> and the slt;/audio> you need to insert the prompt text of the element that the browser does not support.

The element is allowed to use more than one element. The element can link different audio files, and the browser will use the first supported audio file

Audio format and browser support

Currently, the element supports three audio format files: MP3, Wav, and Ogg:

浏览器 MP3 Wav Ogg
Internet Explorer 9+ YES NO NO
Chrome 6+ YES YES YES
Firefox 3.6+ NO YES YES
Safari 5+ YES YES NO
Opera 10+ NO YES YES

The MIME type of the audio format

Format MIME-type
MP3 audio/mpeg
Ogg audio/ogg
Wav audio/wav

HTML5 Audio tag

Label Describe
<audio> The sound content is defined
<source> A multimedia resource is specified, which can be multiple, and is used in the hashtags of slt;video> and slt;audio?gt;

Related articles

HTML DOM Reference Manual: HTML DOM Audio Object