Format Code Now
/
Web & markupMusic Code Generator Next: Image Splitter ›

Music Code Generator for a Website

WM-114

Enter the address of an audio file you host and copy the HTML audio element for it. Choose controls, autoplay, loop, muted, preload and width.

Runs in your browser. Nothing is uploaded.

Audio file

HTML code

Elementaudio
File typeaudio/mpeg
Notesnone

HTML

<audio src="https://example.com/audio/song.mp3" controls preload="metadata" aria-label="Song preview">
  Your browser does not support the audio element. <a href="https://example.com/audio/song.mp3">Download the audio file</a>.
</audio>

How to use it

  1. Enter the address of the audio file. Use http, https or a relative path.
  2. Optionally add an accessible name that screen readers will announce.
  3. Choose the controls, autoplay, loop, muted and preload settings.
  4. Press Copy and paste the code into your page.

What the code is

The output is an HTML5 audio element, the built-in way to play sound on a web page with no plugin. With the src style the file address sits on the audio element. With the source style it sits on a source element with a type, which lets you add more sources by hand. A fallback line with a download link is added for browsers without audio support.

What this tool does not do

It only builds text. It does not load, play or check the file, and there is no preview, so nothing is requested from the address you type. It cannot embed streaming services or third-party players. The file type is guessed from the extension and written only in the source style. Whether the file plays depends on the browser supporting its format.

Error messages and what to do

MessageWhat it meansFix
Enter the address of an audio file.The address field is empty.Type the web address or path of your audio file.
The address cannot contain spaces or control characters. Write a space as %20.The address has a space or an invisible character.Replace each space with %20.

Questions people ask

How do I add background music to a website?

Host the audio file, paste the generated audio element into your page and set the options you want. Autoplay with sound is blocked by most browsers, so visitors usually need to press play.

Why does autoplay not work?

Most browsers block audio that starts on its own until the visitor has interacted with the page. Setting muted allows autoplay, but then there is no sound until the visitor unmutes the player.

Which audio formats can I use?

MP3 is the most widely playable. The tool recognizes mp3, ogg, oga, wav, m4a, aac, flac and weba from the extension. Whether a given file plays depends on the visitor's browser.

What does preload do?

Preload hints how much of the file the browser should fetch early. None fetches nothing until play, metadata fetches only details such as the length, and auto lets the browser fetch the whole file.

Can I use a link to a file on another site?

You can write any http or https address, but the other site must allow it, and you need the right to use the file. This tool does not check the address or load the file.

Is the address safe to paste into the code?

The address and the accessible name are HTML-escaped, so quotes and angle brackets cannot break the attributes. Addresses starting with javascript: or data: are refused.

About this tool

Writes an HTML5 audio element for a file you host yourself. The tool only builds text: it does not load, play or check the file, and no preview is shown, so nothing is requested from the address you type. The address must be http, https or a relative path with no spaces, and it is HTML-escaped. The type is guessed from the file extension (mp3, ogg, oga, wav, m4a, aac, flac, weba) and written only in the source element style. Playback depends on the browser supporting the file format. Streaming services and embedded third-party players are not covered.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.