65.9K
CodeProject is changing. Read more.
Home

Background Music in HTML 5

starIconstarIconstarIconstarIconemptyStarIcon

4.00/5 (2 votes)

Jul 17, 2011

CPOL
viewsIcon

78959

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:

<!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.