<audio> - HTML CSS HTML Tag

HTML CSS examples for HTML Tag:audio

Description

The <audio> element cab embed audio content in an HTML document.

Summary

Placement Block
Content <source>, <track>, and text
Start/End Tag Start tag: required, End tag: required
Version New in HTML5

Tag-Specific Attributes

The following table shows the attributes that are specific to the <audio> tag.

Attribute ValueDescription
autoplay autoplay Boolean attribute sets if audio will automatically start playing as soon as it can do so without stopping to finish loading the data.
controls controls If specified, the browsers will display controls to allow the user to control audio playback, such as play/pause, volume, etc.
loop loop Boolean attribute sets if audio will automatically start over again, upon reaching the end.
muted mutedBoolean attribute sets if audio will be initially silenced. Default false.
preload autometadatanone Provides a hint to the browser about whether to download of the audio itself or its metadata.
src URL Sets the location of the audio file. Alternatively, you can use the preferred <source> tag as it allows for multiple options.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html lang="en">
 <head>
  <title>Example of HTML audio Tag</title>
 </head><!-- w w  w .j  av a  2  s.  co m-->
 <body>
  <audio controls="controls" src="your.mp3">
    Your browser does not support the HTML5 audio element.
  </audio>
 </body>
</html>

An audio, using the browser default set of controls, with alternative sources.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html lang="en">
 <head>
  <title>Example of HTML audio Tag with Alternate Sources</title>
 </head><!--  w w w. j av  a2  s  . co  m-->
 <body>
  <audio controls="controls">
   <source src="your.mp3" type="audio/mpeg">
   <source src="your.ogg" type="audio/ogg"> Your browser does not support the HTML5 audio element.
  </audio>
 </body>
</html>

Related Tutorials