Curriculum
Course: HTML Basic
Login

Curriculum

HTML Basic

HTML Introduction

0/1

HTML Editors

0/1

HTML Elements

0/1

HTML Attributes

0/1

HTML Headings

0/1

HTML Paragraphs

0/1

HTML Styles

0/1

HTML Formatting

0/1

HTML Quotation

0/1

HTML Comments

0/1

HTML Colors

0/1

HTML Favicon

0/1

HTML Page Title

0/1

HTML Block and Inline

0/1

HTML Iframes

0/1

HTML Java Script

0/1

HTML File Paths

0/1

HTML - The Head Element

0/1

HTML Style Guide

0/1

HTML Entities

0/1

HTML Symbols

0/1
Text lesson

HTML Audio

The HTML <audio> Element

To play an audio file using HTML, utilize the <audio> element:

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>

HTML Audio – How It Works

The controls attribute adds audio controls such as play, pause, and volume.

The <source> element allows specification of alternative audio files that browsers can choose from, with the first recognized format being used.

Text between the <audio> and </audio> tags appears only in browsers that do not support the <audio> element.

HTML <audio> Autoplay

To automatically start playing an audio file, use the autoplay attribute:

Example

<audio controls autoplay>
  <source src=”horse.ogg” type=”audio/ogg”>
  <source src=”horse.mp3″ type=”audio/mpeg”>
Your browser does not support the audio element.
</audio>
Note that in Chromium browsers, autoplay is generally restricted, but muted autoplay is consistently permitted.

Include the muted attribute after autoplay to enable your audio file to start playing automatically (but muted):

Example

<audio controls autoplay muted>
  <source src=”horse.ogg” type=”audio/ogg”>
  <source src=”horse.mp3″ type=”audio/mpeg”>
Your browser does not support the audio element.
</audio>

Browser Support

The numbers in the table indicate the earliest browser version that fully supports the <audio> element.

da3fa333-bb23-4831-ba7e-a34a4864d628

HTML Audio Formats

The three supported audio formats are MP3, WAV, and OGG. Browser support varies for each of these formats.

Browser

MP3

WAV

OGG

Edge/IE

YES

YES*

YES*

Chrome

YES

YES

YES

Firefox

YES

YES

YES

Safari

YES

YES

NO

Opera

YES

YES

YES

*From Edge 79 

HTML Audio – Media Types

File Format

Media Type

MP3

audio/mpeg

OGG

audio/ogg

WAV

audio/wav

HTML Audio – Methods, Properties, and Events

The HTML DOM provides methods, properties, and events specifically for the <audio> element.

These enable tasks such as loading, playing, and pausing audio, as well as adjusting settings like duration and volume. Additionally,

DOM events are available to notify you when an audio starts playing, is paused, and more.

HTML Audio Tags

Tag

Description

<audio>

Defines sound content

<source>

Defines multiple media resources for media elements, such as <video> and <audio>