Skip to content
← Back to Community
how do you embed mp3 files into html?
Profile icon
staticvoidliam7

so i want to play a song in the background of my website.
how would i do that?

Voters
Profile icon
HMNGS
Profile icon
Crozn
Profile icon
MichaelJames9
Profile icon
LePythonneur
Profile icon
staticvoidliam7
Comments
hotnewtop
Profile icon
mwilki7

Found this online and it works okay, just not multiple sounds at once

function sound(src) { this.sound = document.createElement("audio"); this.sound.src = src; this.sound.setAttribute("preload", "auto"); this.sound.setAttribute("controls", "none"); this.sound.style.display = "none"; document.body.appendChild(this.sound); this.play = function(){ this.sound.play(); } this.stop = function(){ this.sound.pause(); } }

Usage:

var background_music = new sound("name_of_your_sound.mp3"); background_music.play();
Profile icon
SixBeeps

Use the tag

Profile icon
staticvoidliam7
Profile icon
lilshav

legend has it they never returned