Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML5 Audio (audio)

HTML5 Audio (audio)


HTML5 provides a standard for playing audio files.


Audio on the Internet

Until now, there has been no standard for playing audio on web pages.

Today, most audio is played through plugins (such as Flash). However, not all browsers have the same plugins.

HTML5 specifies a standard for embedding audio elements in web pages, namely using the


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Internet Explorer 9+, Firefox, Opera, Chrome, and Safari all support the

Note: Internet Explorer 8 and earlier IE versions are not supported.


HTML5 Audio - How It Works

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

Example

<

audio

controls

<

source

src

=

"

horse.ogg

"

type

=

"

audio/ogg

"

<

source

src

=

"

horse.mp3

"

type

=

"

audio/mpeg

"

Your browser does not support the audio element.

audio

Try it »

The control attribute provides controls for play, pause, and volume.

in Between them, you need to insert the prompt text for browsers that do not support the


Audio Formats and Browser Support

Currently,

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

MIME Types for Audio Formats

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

HTML5 Audio Tags

tag Description
Defines sound content
specifies multimedia resources, which can be multiple, in the