0% found this document useful (0 votes)
12 views8 pages

HTML Audio

The HTML <audio> element is used to embed audio files in web pages, providing controls for play, pause, and volume. It supports multiple audio formats including MP3, WAV, and OGG, with browser compatibility varying by format. The document also explains attributes like autoplay and muted autoplay for automatic playback of audio files.

Uploaded by

karavej314
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views8 pages

HTML Audio

The HTML <audio> element is used to embed audio files in web pages, providing controls for play, pause, and volume. It supports multiple audio formats including MP3, WAV, and OGG, with browser compatibility varying by format. The document also explains attributes like autoplay and muted autoplay for automatic playback of audio files.

Uploaded by

karavej314
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

 Tutorials  Exercises  Services   Sign Up Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C

HTML Audio
❮ Previous Next ❯

The HTML <audio> element is used to play an audio file on a web page.

The HTML <audio> Element


To play an audio file in HTML, use 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>

Try it Yourself »

HTML Audio - How It Works


The controls attribute adds audio controls, like play, pause, and volume.

The <source> element allows you to specify alternative audio files which the browser
may choose from. The browser will use the first recognized format.
The text between the <audio> and </audio> tags will only be displayed in browsers
 Tutorials  Exercises  Services 
that do not support the <audio> element.
 Sign Up Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C

HTML <audio> Autoplay


To start an audio file automatically, 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>

Try it Yourself »

Note: Chromium browsers do not allow autoplay in most cases. However, muted
autoplay is always allowed.

Add muted after autoplay to let your audio file 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>

Try it Yourself »
Browser
 Tutorials Support
Exercises  Services   Sign Up Log in

HTML CSS
The numbers inJAVASCRIPT SQLthe first
the table specify PYTHON
browser JAVA PHP fullyHOW
version that TO
supports W3.CSS
the C
<audio> element.

Element

<audio> 4.0 9.0 3.5 4.0 10.5

HTML Audio Formats


There are three supported audio formats: MP3, WAV, and OGG. The browser support
for the different formats is:

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
Tutorials  - Methods,
Exercises  Services  Properties,
 and
Sign Up Log in


Events
HTMLCSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C

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

This allows you to load, play, and pause audios, as well as set duration and volume.

There are also DOM events that can notify you when an audio begins to play, is
paused, etc.

For a full DOM reference, go to our HTML Audio/Video DOM Reference.

HTML Audio Tags


Tag Description

<audio> Defines sound content

<source> Defines multiple media resources for media elements, such as


<video> and <audio>

❮ Previous Next ❯

W3schools Pathfinder
Track your progress - it's free! Sign Up Log in

ADVERTISEMENT
 Tutorials  Exercises  Services   Sign Up Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C

COLOR PICKER
 Tutorials  Exercises  Services   Sign Up Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C


ADVERTISEMENT

ADVERTISEMENT ADVERTISEMENT
 Tutorials  Exercises  Services   Sign Up Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C

 SPACES UPGRADE AD-FREE

NEWSLETTER GET CERTIFIED CONTACT US

Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
W3.CSS Tutorial
Bootstrap Tutorial
PHP Tutorial
Java Tutorial
C++ Tutorial
jQuery Tutorial

Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
W3.CSS Reference
Bootstrap Reference
PHP Reference
HTML Colors
Java Reference
Angular Reference
jQuery Reference

Top Examples Get Certified


HTML Certificate
HTML Examples CSS Certificate

 CSS Examples
Tutorials  Exercises 
JavaScript Examples
Services  JavaScript Certificate

Front End Certificate
Sign Up Log in
How To Examples SQL Certificate
HTML
 CSS SQL Examples
JAVASCRIPT SQL PYTHON Python
JAVACertificate
PHP HOW TO W3.CSS C
Python Examples PHP Certificate
W3.CSS Examples jQuery Certificate
Bootstrap Examples Java Certificate
PHP Examples C++ Certificate
Java Examples C# Certificate
XML Examples XML Certificate
jQuery Examples

    

FORUM ABOUT CLASSROOM


W3Schools is optimized for learning and training. Examples might be simplified to
improve reading and learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we
cannot warrant full correctness
of all content. While using W3Schools, you agree to have read and accepted our
terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by


W3.CSS.

You might also like