HTML Tutorial
HTML - Introduction HTML - Basic HTML - Structure HTML - Element HTML - Attributes HTML - Headings HTML - Paragraphs HTML - Styles HTML - Formatting HTML - Phrase Tags HTML - Quotations HTML - Comments HTML - Colors HTML - CSS HTML - Links HTML - Images HTML - Tables HTML - List HTML - Inline elements HTML - Block elements HTML - Classes HTML - Id HTML - Javascript HTML - File Path HTML - Iframe HTML - Responsive HTML - Computer Code HTML - Head tag HTML - Events HTML - Url Encoding HTML - Entities HTML - Validation
HTML Forms
HTML - Forms HTML - Form Elements HTML - Input types HTML - Input Attributes
HTML5
HTML5 - Introduction HTML5 - New Elements HTML5 - Semantics HTML5 - Style Guide
HTML Media
HTML - Video HTML - Audio HTML - Embed Multimedia
HTML Graphics
HTML - Canvas HTML - SVG
HTML APIs
HTML - Geolocation HTML - Drag & drop HTML - Web Storage HTML - Web Workers
HTML References
HTML - Tag Reference HTML - Tag by Category HTML - Attributes HTML - Global Attributes HTML - Events HTML - Language Codes HTML - Country Codes HTML - URL Encoding HTTP Methods HTTP Status Codes <input> types

HTML5 Audio

Before HTML5, an audio could only be played in a browser with a plug-in like flash.

The HTML5 specification introduced the audio element for the purpose of playing audios.

The HTML5 <audio> element embeds a media player which supports audio playback into the document.


HTML <audio> Element

The <audio> element is used to embed audio in web pages.

Run code

The controls attribute allow the user to control audio playback, including volume, seeking, and pause/resume playback.

The <source> element specifies alternative media resources for the audio. The browser will use the first recognized format.

Any text between <audio> and </audio> will be displayed in browsers that do not support the <audio> tag.



HTML Audio - The autoplay Attribute

The autoplay attribute specifies that the audio automatically begins to play back as soon as it can do so without stopping to finish loading the data.

Run code

HTML Audio - The loop Attribute

The loop attribute specifies that the browser will automatically seek back to the start upon reaching the end of the audio.

Run code

HTML Audio - Media Types

File Format Media Type
MP3 audio/mpeg
OGG audio/ogg
WAV audio/wav

HTML5 Audio Attributes

Attribute Description
autoplay A boolean attribute specifies that the audio automatically begins to play back as soon as it can do so without stopping to finish loading the data
controls A boolean attribute specifies that the browser will offer controls to allow the user to control audio playback, including volume, seeking, and pause/resume playback
loop A boolean attribute specifies that the browser will automatically seek back to the start upon reaching the end of the audio
muted A boolean attribute specifies that the audio should be muted
preload This enumerated attribute is intended to provide a hint to the browser about what the author thinks will lead to the best user experience
src Specifies the URL of the audio file