audio

< html‎ | elements
Jump to: navigation, search

audio

This article is Ready to Use.


W3C Recommendation

Summary

The audio element (<audio>) is used for playing audio files and may display a minimal media player user interface.


Overview Table

DOM Interface HTMLAudioElement

Extensive documentation on manipulating the element may be found on the HTMLAudioElement page.


HTML Attributes

  • autoplay = "autoplay" or "" (empty string) or empty
    Instructs the UA to automatically begin playback of the audio stream as soon as it can do so without stopping.
  • preload = "none" or "metadata" or "auto" or "" (empty string) or empty
    Represents a hint to the UA about whether optimistic downloading of the audio stream itself or its metadata is considered worthwhile.
    • "none": Hints to the UA that the user is not expected to need the video, or that minimizing unnecessary traffic is desirable.
    • "metadata": Hints to the UA that the user is not expected to need the audio stream, but that fetching its metadata (duration and so on) is desirable.
    • "auto": Hints to the UA that optimistically downloading the entire audio stream is considered desirable.
      Specifying the empty string is equivalent to specifying the value "auto".
  • controls = "controls" or "" (empty string) or empty
    Instructs the UA to expose a user interface for controlling playback of the audio stream.
  • loop = "loop" or "" (empty string) or empty
    Instructs the UA to seek back to the start of the audio stream upon reaching the end.
  • mediagroup = string
    Instructs the UA to link multiple videos and/or audio streams together.
  • src = URL potentially surrounded by spaces
    The URL for the audio stream.


Accessibility

Authors should ensure that the information and user interface components must be presentable to users in ways they can perceive (WCAG 2.0 - Principle 1: Perceivable). This includes providing alternatives for time-based media Guideline 1.2.


Formats and Codecs

The specification does not require a specific audio codec to be supported by all user agents. Using both Ogg/Vorbis and MP4/AAC seems to cover most user-agents, however. See the Audio format support on Wikipedia.

Examples

View live exampleplay a mp3 on webpage

HTML

<audio controls src="http://freedownloads.last.fm/download/533190714/she%2Bso%2Bfly.mp3" type="audio/mp3">
</audio>



Related specifications

Specification Status Related Changes
HTML 5.1 W3C Working Draft
HTML 5 W3C Recommendation

See also

Other articles

Attribution

This article contains content originally from external sources.

Portions of this content come from the Mozilla Developer Network
Error creating thumbnail: File missing
: Article

Portions of this content come from the Microsoft Developer Network: [Windows Internet Explorer API reference Article]