Skip to content

Add music to your HTML web page

You can add background music to your web page in HTML using <embed > or <audio> tag.

The <embed> tag is used to embed multimedia content into an HTML document. You can set loop as true as autostart as true to make sure your music is played when you web page is opened and it doesn’t stop.

Advertisements
<embed src="/music/bgm.mp3" loop="true" autostart="true" width="5" height="0">

Another way to embed audio to your html page is to use <audio> tags.

<audio controls="controls">
    <source src="media/bgm.mp3" type="audio/mpeg">
    <source src="media/bgm.ogg" type="audio/ogg">
    Your browser does not support the HTML5 Audio element.
</audio>
Advertisements

We can specify multiple sources of audio inside the <audio> tag to make sure your audio plays in all browsers.

See also  How to handle paste event in textarea HTML element?
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.