Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / HTML5

Background Music in HTML 5

4.00/5 (2 votes)
17 Jul 2011CPOL 79K  
Playing background music in HTML 5.

In the following simple trick, I am going to show you how to play audio in the background using HTML 5:


XML
<!DOCTYPE html>
<html>
  <link rel="stylesheet" href="styles.css">
  <title>Background Music</title>

  <audio autoplay loop>
      <source src="johann_sebastian_bach_air.ogg">
      <source src="johann_sebastian_bach_air.mp3">
  </audio

  <h1>You're hooked on Bach!</h1>
</html>

Kindly change the audio source name to your own.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)