logo Learn HTML
  • Home
  • Tutorials
  • Practice
  • Quiz
  • Projects
  • About
  • Contact

HTML Course

  • HTML HOME
  • HTML Introduction
  • HTML Basic
  • HTML Element
  • HTML Attributes
  • HTML Headings
  • HTML Paragrapha
  • HTML Style
  • HTML Formattin
  • HTML Quotations
  • HTML Colors
  • HTML Css
  • HTML Links
  • HTML Image
  • HTML Favicon
  • Page Tittle
  • HTML Tables
  • HTML Lists
  • Block & Inline
  • HTML Div
  • HTML Classes
  • HTML Id
  • HTML Buttons
  • HTML Iframes
  • HTML File Paths
  • HTML Head
  • HTML Layout
  • HTML Symbols
  • HTML Emojis
  • HTML URL Encode
  • HTML VS XHTML
  • HTML FROM
  • HTML Form
  • Form Attributes
  • Form Elements
  • HTML Input Types
  • HTML Input Attributes
  • Input Form Attributes
  • HTML Graphics
  • HTML Canvas
  • HTML SVG
  • HTML Media
  • HTML Media
  • HTML Video
  • HTML Audio
  • HTML Plug-ins
  • HTML Youtube
  • HTML APIS
  • HTML Web APIS
  • HTML Geolocation
  • HTML Drag & Drop
  • Web Storage
  • Web Workers
  • HTML SSE
  • HTML Examples
  • HTML Examples
  • HTML Editor
  • HTML Quiz
  • HTML Exercises
  • HTML References
  • HTML Tag List
  • HTML Attributes
  • HTML Global Attributes
  • HTML Brower Support
  • HTML Events
  • HTML Colors
  • HTML Canvas
  • HTML Audio & Video
  • HTML Doctypes
  • HTML Character Sets
  • HTML URL Encode
  • Language Codes
  • HTTP Messages
  • HTTP Methods
  • PX to EM Converter
  • keyboard Shortcuts

HTML Audio – Play Sound Files in Browser

The HTML <audio> element allows you to play sound files, music, or podcasts directly on a web page without any third-party plugins.


The <audio> Element

To embed audio, use the <audio> tag. Like the <video> tag, it uses the <source> tag to provide multiple file formats.

Basic Example:

<audio controls>
<source src="music.mp3" type="audio/mpeg">
<source src="music.ogg" type="audio/ogg">

Your browser does not support the audio element.

</audio>

How It Works

  • controls: Displays the standard browser player (Play, Pause, Volume, Seek).

  • </audio>: You can list multiple formats. The browser will play the first format it supports.

  • Fallback Text: Shown if the browser is too old to support HTML5 audio.


Autoplay and Muted Attributes

Similar to video, audio can start automatically, but browsers have strict rules:

  • autoplay: Starts the audio automatically (may be blocked unless the user interacts first).

  • muted: Plays audio without sound.

Example of Muted Autoplay:

<audio controls autoplay muted>
<source src="music.mp3" type="audio/mpeg">
</audio>

Supported Audio Formats

The main formats supported by HTML5 are MP3, WAV, and OGG:

Browser MP3 WAV OGG
ChromeYESYESYES
EdgeYESYESYES
FirefoxYESYESYES
SafariYESYESNo
OperaYESYESYES

Media Types (MIME Types)

  • MP3: audio/mpeg

  • OGG: audio/ogg

  • WAV: audio/wav


HTML Audio Tag Reference

TagDescription
<audio>Defines sound content, like music or other audio streams.
<source>Defines multiple media resources for audio and video.

Interactive Control (JavaScript)

You can control audio using JavaScript, just like video. Common methods include:

  • play(): Starts the audio.

  • pause(): Pauses the audio.

  • volume: Adjusts loudness (0.0 to 1.0).

Try It Your Self

Sign Up For New
Update

HTML Basic
  1. HTML Basic
  2. HTML Element
  3. HTML Attributes
  4. HTML Headings
  5. HTML Paragrapha
  6. HTML Tables
  7. HTML Lists
HTML Advance
  1. HTML Div
  2. HTML Classes
  3. HTML Id
  4. HTML Buttons
  5. HTML Iframes
  6. HTML Symbols
  7. HTML Emojis