WWW FAQs: How do I play music without displaying a player in the web page?

2008-08-18: it's easy to embed music in a page. See the article How do I embed sound and music in a page? for the basics. But embedding music without displaying player controls is a bit trickier. Historically, you could use the hidden attribute of the embed tag to hide the player, but this doesn't work reliably in Firefox, especially if you are also using JavaScript to control the player. So I recommend that you set the width and height attributes to 0, like this:

<embed src="mysong.mp3"
 width="0" height="0"

Although this is enough to hide the player effectively from the user, it may still take up a pixel or two in your page layout, so place the embed element just before the close of your body element.

As always, think carefully before embedding music in a page. Most users find embedded music very annoying and repetitious and will not thank you for interfering with their preferred music while they browse the web.

Legal Note: yes, you may use sample HTML, Javascript, PHP and other code presented above in your own projects. You may not reproduce large portions of the text of the article without our express permission.

Got a LiveJournal account? Keep up with the latest articles in this FAQ by adding our syndicated feed to your friends list!