Background music | SoloLearn: Learn to code for FREE!


Background music

Is it possible to code music that will play in the background in HTML, so that when a viewer opens my website the music will start playing automatically in the background. Thank-you in advance.

7/1/2020 4:35:16 PM


7 Answers

New Answer


Yes, it's possible… just add the autoplay attribute to the audio's object. However, the feature is limited on the sololearn app, you have to bind the play() method of the Audio's object to a HTML event, maybe onclick or when something done

+3 I created this code and it's working with music. You can get a reference from here and start coding. When a user opens a website means when body load (onload event in HTML) just play the music.


I am not making website here, in Sololearn. I'm using an editor called "Sublime Text".


Can you show me the code, please?


If I understand correctly, the background music is working using nit only HTML , but JS as well. Am I right?


An also, may I ask another question, please? How can I make a button have more than one color? At the moment, I am making the project of my dream. By September it should be finished.