HTML and CSS Reference
In-Depth Information
If you want to allow the user to control sound play, unless you have utilized JavaScript
to control this, you may opt to show controls with the same named attribute. Depending on
the browser, these controls may look quite different, as shown next.
<audio src="http://htmlref.com/ch2/music.wav" controls></audio>
As with the
video
element, you also have
autobuffer
and
autoplay
attributes for the
audio
element. Unfortunately, just like
video
, there are also
audio
format support issues,
so you may want to specify different formats using
<source>
tags:
<audio controls autobuffer autoplay>
<source src="http://htmlref.com/ch2/music.ogg" type="audio/ogg">
<source src="http://htmlref.com/ch2/music.wav" type="audio/wav">
</audio>
A complete example is shown here:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>
HTML5 audio examples
</title>
</head>
<body>
<h1>
Simple Audio Examples
</h1>
<h2>
wav Format
</h2>
<audio src="http://htmlref.com/ch2/music.wav" controls></audio>
<h2>
ogg Format
</h2>
<audio src="http://htmlref.com/ch2/music.ogg" controls></audio>
<h2>
Multiple Formats and Fallback
</h2>
<audio controls autobuffer autoplay>
<source src="http://htmlref.com/ch2/music.ogg" type="audio/ogg">
<source src="http://htmlref.com/ch2/music.wav" type="audio/wav">
<!--[if IE]>
<bgsound src="http://htmlref.com/ch2/music.wav">
<![endif]-->
</audio>
</body>
</html>
O
NLINE
http://htmlref.com/ch2/audio.html