OxyPages

How To Add Audio To HTML With A Player That Works Everywhere

How To Add Audio To HTML With A Player That Works Everywhere

How to add audio to HTML with one tag: the formats that play in every browser, why autoplay fails, and the fix when a player shows up but stays silent.

The OxyPages Team · · 9 min read

You've got a page, maybe one an AI wrote for you this morning, and a sound file that belongs on it. A song, a podcast clip, a voice note, a demo for a client. You paste in the tag the AI suggested, a neat little player appears, and you press play.

Nothing happens. Or it plays on your laptop and goes silent the moment the page is online.

The code is the easy part. To add audio to an HTML page you need one tag and one attribute, and every current browser has a player built in. What goes wrong is almost never the tag. It's where the file lives, which format you picked, and whether the server can send a song in pieces.

So here's the tag, the formats that play everywhere, the attributes worth knowing, and the reasons a player shows up but won't play. If paths and folders are new to you, the guide to HTML file basics is worth five minutes first, because that's where most audio problems start.

TL;DR: Use <audio controls src="song.mp3"></audio> and put song.mp3 in the same folder as the page. MP3 plays in every current browser. Upload the audio file with the page, or the player shows and stays silent. Don't rely on autoplay with sound, because browsers block it until the visitor taps something. If listeners can't skip ahead, the host isn't answering range requests, and Safari needs those.

The One Tag You Need: The HTML Audio Element

The <audio> element is a built-in HTML audio player. You point it at a sound file, add controls, and the browser draws play, pause, a timeline and volume for you.

This is the whole thing:

<audio controls src="song.mp3">
  Your browser can't play this audio. <a href="song.mp3">Download the MP3</a> instead.
</audio>

src is the address of the file. song.mp3 with no folder in front means "next to this page".

controls tells the browser to show its player. Leave it out and the element is invisible, which catches a lot of people out.

The text between the tags only appears in a browser that can't handle the element at all. That's almost nobody today, but a download link costs nothing.

How To Add Audio To An HTML Page, Step By Step

Here's the walkthrough I'd follow for any page, whatever tool made it.

  1. Make a folder for the site and put your index.html inside it.
  2. Put the audio file in the same folder. Rename it to something short with no spaces or capitals, like song.mp3.
  3. Paste the tag into index.html wherever the player should sit.
  4. Test it on your own machine. Double-click index.html, press play and drag the timeline.
  5. Upload the whole folder, not just the page. The audio file has to travel with the HTML.
  6. Test the live address on a phone. Use an iPhone if you can, since Safari is the fussiest browser about audio.

Your folder should look like this before you upload:

my-site/
  index.html
  song.mp3

You can keep audio in its own folder instead. Make it audio/song.mp3 on disk and write src="audio/song.mp3" in the tag. The path has to match the folder exactly.

For step 5, how to get an HTML file online covers the upload side for several hosts.

Which Audio Formats Play In Every Browser?

MP3 plays in every current browser, so it's the format to reach for. M4A, which is AAC audio, is just as safe, and it's what an iPhone's Voice Memos app saves.

FormatExtensiontype valuePlays inWorth knowing
MP3.mp3audio/mpegEvery current browserThe safe default. About 1 MB per minute at 128 kbps
AAC.m4aaudio/mp4Every current browserSame quality as MP3 at a smaller size
Ogg Vorbis.oggaudio/oggChrome, Firefox, Edge, Safari 18.4 and laterOlder iPhones and Macs that haven't updated won't play it
WAV.wavaudio/wavEvery current browserUncompressed, about 10 MB per minute. Convert it first

Safari only gained full Ogg support in version 18.4, released in 2025, according to caniuse in November 2026. Plenty of phones are older than that, so never ship Ogg as your only file.

WAV plays fine. It's just huge. A three-minute WAV is around 30 MB, the same track as an MP3 is under 3 MB, and every listener on mobile data pays for the difference.

Offering More Than One Format

You can list several files and let the browser pick the first one it can play, using <source> lines instead of src:

<audio controls preload="metadata">
  <source src="song.ogg" type="audio/ogg">
  <source src="song.mp3" type="audio/mpeg">
  <a href="song.mp3">Download the MP3</a>
</audio>

The type lets the browser skip a format it can't play without downloading anything, so always include it. MDN's reference for the audio element

For most pages this is overkill. One MP3 plays everywhere.

The Attributes Worth Knowing

Five attributes cover nearly everything you'll want an HTML audio player to do.

AttributeWhat it doesWhen to use it
controlsShows the browser's play, pause, timeline and volumeAlmost always
preload="metadata"Fetches only the length and basic details until someone presses playPages with several tracks, or listeners on mobile data
preload="auto"Lets the browser download the whole file in advanceOne short clip that should start instantly
loopJumps back to the start when the track endsBackground music, ambient sound
mutedStarts with the sound offRarely for audio. Mostly a video trick
autoplayTries to start playback on its ownDon't rely on it, see below

preload is a hint, not an order. MDN notes that browsers may ignore it, and each one has its own default. I set metadata on any page with more than one player, so eight tracks don't quietly pull 30 MB before anyone presses anything.

One trap with muted: writing muted="false" still mutes the player. If the word is there at all, it's on.

Why Won't My Audio Autoplay?

Because browsers block audio that starts with sound before the visitor has interacted with the page. Add autoplay and, on most first visits, nothing happens.

The rules vary by browser, but MDN sums up the pattern: media may autoplay if it's muted, if the visitor has already clicked or tapped something on the site, or if the browser has learned they often play media there. Otherwise it will likely be blocked. MDN's autoplay guide for media and Web Audio

Muted autoplay is allowed, but a muted song is silence, so it doesn't help.

My verdict is blunt: don't build a page that depends on autoplay with sound. Put a clear play button where people will see it. A page that starts playing music in an open office gets closed, which is exactly why browsers made the rule.

Why Does The Player Show But Not Play?

Why Does The Player Show But Not Play? - OxyPages

Nearly always because the browser can't reach the file. The player drawing itself proves the tag works, and says nothing about the audio. Check these in order:

  • The file wasn't uploaded. Only the HTML went online. This is the number one cause by a long way.
  • The path doesn't match. The tag says song.mp3 and the file is in a folder called audio, or the other way round.
  • Capital letters. A Mac doesn't care whether the file is Song.MP3 or song.mp3. Most web servers do, so it works at home and breaks online.
  • A path that names your computer. Anything starting file:/// or C: only exists on your machine.
  • A cloud drive share link. A Google Drive or Dropbox share link opens a viewer page, not the sound file.
  • An http:// file on an https:// page. Browsers may block that as mixed content.

To see which one it is, right-click the page, choose Inspect, open the Console tab and press play. A 404 means the browser found nothing at that address.

Why Can't Listeners Skip Ahead?

Why Can't Listeners Skip Ahead? - OxyPages

If dragging the timeline does nothing, or Safari won't play the file at all, the server isn't answering range requests. A range request is the browser asking for one slice of the file, say from minute two onward, instead of the whole thing.

The server should reply with status 206 and just that slice. Some hosts send the full file every time. Chrome often copes. Safari often won't, and Apple's developer notes say servers need byte-range support for iOS to seek through media.

You can check any host in ten seconds from Terminal:

curl -s -o /dev/null -w "%{http_code}\n" -r 0-99 https://your-site.example.com/song.mp3

206 means the host handles ranges. 200 means it sent the whole file and seeking will be unreliable.

Most static hosts get this right. OxyPages does too: audio is served with Accept-Ranges: bytes and 206 replies, which we checked against a live file in November 2026. Caching plugins, home-made servers and older shared hosts are where it tends to break.

Styling The Player And A Custom Play Button

The built-in player is narrow and sits inline with your text. Two rules fix that:

<audio controls src="song.mp3" style="display: block; width: 100%; max-width: 600px;"></audio>

display: block puts it on its own line, and width: 100% fits it to a phone screen. You can add margins and a border, but you can't restyle the buttons inside, because each browser draws its own. To keep styles out of the tag, linking a CSS file to your HTML shows where they go.

A Basic Custom Play Button

For your own button instead of the browser's player, leave out controls and drive the element with a few lines of JavaScript:

<audio id="track" src="song.mp3" preload="metadata"></audio>
<button id="play-button" type="button">Play</button>

<script>
  const track = document.getElementById("track");
  const button = document.getElementById("play-button");

  button.addEventListener("click", () => {
    if (track.paused) {
      track.play();
    } else {
      track.pause();
    }
  });

  track.addEventListener("play", () => (button.textContent = "Pause"));
  track.addEventListener("pause", () => (button.textContent = "Play"));
</script>

A click counts as the visitor interacting, so autoplay rules don't get in the way, and the label flips back to Play when the track ends. The script sits at the end of the body so the elements exist when it runs, and how to link JavaScript to HTML explains why that order matters.

Keep this for one track. The built-in player gives you seeking, volume and keyboard support free.

If you just want an address to paste into the src, you can skip the folder entirely.

The drop zone on the OxyPages homepage takes one MP3, M4A, WAV or OGG file up to 20 MB with no account. It builds a page with a player, plus a Direct link button pointing at the file itself. Paste that link into your own tag as the src and it plays.

Without an account the link lasts 30 minutes, so it's for trying, not for a page you've shared. Claiming it with a free account keeps it online for good and gives it a new address, so copy the new direct link into your tag afterwards.

Now the limits. Only upload audio you made or have the rights to share. OxyPages is website hosting, not a music streaming service or a podcast host, and heavy streaming falls under its fair-use rules. A podcast that needs an RSS feed and a listing in Apple Podcasts or Spotify belongs on a podcast host. A full album with play counts and comments suits SoundCloud or Bandcamp better.

What To Do Next

Start from what you're holding.

  • A page and a file: put them in one folder, add the tag, test it, then upload the folder.
  • Plays at home, not online: check the file was uploaded and the name matches exactly, capitals included.
  • Won't seek, or Safari stays silent: run the curl test. A 200 means the host is the problem, not your code.
  • You only need a link that plays: turn your MP3 into a URL with a player, no account needed to try it.

Adding audio comes down to one tag and a file sitting exactly where the tag says it is. Get the path right and the rest is detail.

FAQ

Can I Use An MP3 Hosted On Another Website?

Yes. The audio element can play a file from another domain without special setup, as long as the address points straight at the file. The catch is that if the file moves or disappears, your player goes silent. Only use files you have the rights to.

Why Does My Audio Play On Desktop But Not On iPhone?

Usually the file is Ogg and the iPhone runs Safari older than 18.4, or the server doesn't answer range requests. Switch to MP3, then run the curl test against the live file.

How Do I Make The Audio Player Fill The Width Of The Page?

Add style="display: block; width: 100%;" to the audio tag, or the same two rules in your stylesheet. A max-width stops it getting absurdly long on a big monitor.

Can I Add Audio To An HTML Page Without Writing Code?

Yes. Upload the file to a host that builds a player page for you and share that page's link. If you need a file address for an existing page, use the host's direct link to the file as the src, and check the link is permanent before you publish.

Try It Now

Still Here? Drop It In.

The whole pitch fits in one sentence: your HTML, on a link, in seconds.

Drag and drop your HTML files, a folder, a ZIP, your app's build folder, a PDF, an image or an MP3

or ·

No account needed. Your unclaimed website stays live for 30 minutes on a free subdomain. Claim it to your account to keep it permanently.

  • No Account Needed
  • Free SSL
  • 30-Minute Unclaimed Link, Claim To Keep It