Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape

HTML Audio

HTML Audio

HTML CODES & EXAMPLES

HTML Audio

Learn how to add audio, music, voice recordings and sound controls to a webpage using HTML.

01

What is HTML Audio?

Introduction to audio in HTML

HTML provides the <audio> element for adding sound and audio content to a webpage. The controls attribute displays browser audio controls such as play, pause and volume.

Important: Use accessible text and appropriate audio formats when adding audio to your website.
02

Basic Audio

Add an audio file to a webpage

basic-audio.html
<audio controls>
  <source src="audio.mp3" type="audio/mpeg">
</audio>
03

Audio Controls

Show browser audio controls

audio-controls.html
<audio
  src="lesson.mp3"
  controls
>
</audio>
04

Audio with Fallback Text

Provide a message when audio is unsupported

audio-fallback.html
<audio controls>

  <source
    src="lesson.mp3"
    type="audio/mpeg"
  >

  Your browser does not support
  the audio element.

</audio>
05

Multiple Audio Formats

Provide different audio formats

multiple-audio.html
<audio controls>

  <source
    src="lesson.mp3"
    type="audio/mpeg"
  >

  <source
    src="lesson.ogg"
    type="audio/ogg"
  >

  Your browser does not support
  the audio element.

</audio>
06

Audio Loop

Repeat the audio automatically

audio-loop.html
<audio
  src="music.mp3"
  controls
  loop
>
</audio>
07

Muted Audio

Start the audio in muted mode

muted-audio.html
<audio
  src="lesson.mp3"
  controls
  muted
>
</audio>
09

Autoplay + Muted

Common pattern for autoplay media

autoplay-muted.html
<audio
  src="background.mp3"
  autoplay
  muted
  loop
>
</audio>
10

Preload Audio

Control how the browser loads audio

preload-audio.html
<audio
  src="lesson.mp3"
  controls
  preload="metadata"
>
</audio>
Preload values: none metadata auto
11

Audio Download Link

Allow users to download an audio file

download-audio.html
<a
  href="lesson.mp3"
  download
>
  Download Audio
</a>
12

Audio Lesson

Create an educational audio lesson

audio-lesson.html
<section>

  <h2>
    Introduction to Computers
  </h2>

  <p>
    Listen to this lesson.
  </p>

  <audio controls>

    <source
      src="computer-fundamentals.mp3"
      type="audio/mpeg"
    >

    Your browser does not support
    audio playback.

  </audio>

</section>
13

Professional Audio Card

Create a styled audio lesson card

audio-card.html
<div class="audio-card">

  <div class="audio-icon">
    🎧
  </div>

  <div>

    <h3>
      Computer Fundamentals
    </h3>

    <p>
      Lesson 01 • Introduction
    </p>

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

  </div>

</div>

<style>

.audio-card{

  display:flex;
  gap:18px;
  align-items:center;
  padding:20px;
  border-radius:16px;
  background:#f5f9ff;
  border:1px solid #dce8f5;

}

.audio-icon{

  width:55px;
  height:55px;
  display:flex;
  align-items:center;
  justify-content:center;
  border-radius:14px;
  background:#1769d5;
  color:#fff;
  font-size:25px;

}

.audio-card h3{
  margin:0 0 5px;
}

.audio-card p{
  margin:0 0 12px;
  color:#718096;
}

</style>
14

Important Audio Attributes

Quick reference

Attribute
Purpose
Example
controls
Shows audio controls
controls
autoplay
Attempts automatic playback
autoplay
loop
Repeats the audio
loop
muted
Starts muted
muted
preload
Controls preload behavior
preload=”metadata”
src
Audio file location
src=”lesson.mp3″
15

Live HTML Audio Runner

Run and preview an audio example

LIVE PREVIEW
`;document.getElementById( "sncecAudioPreview" ).srcdoc=code;}document.addEventListener( "DOMContentLoaded", function(){sncecAudioRun();} );

HTML JavaScript

  • 17/08/2026

Html Codes

  • 16/08/2026

Leave a Reply

Your email address will not be published. Required fields are marked *