Click here to Skip to main content
15,867,308 members
Articles / Web Development / HTML5
Tip/Trick

Background Music in HTML 5

Rate me:
Please Sign up or sign in to vote.
4.00/5 (2 votes)
17 Jul 2011CPOL 78K   4   4
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)


Written By
Software Developer Netiks
Lebanon Lebanon
I have been a programmer for about one year.My power is in asp.net and flash (actionscript 3).I also work on windows application using vb.net and c#.

Comments and Discussions

 
GeneralMy vote of 4 Pin
Ssntosh Chouhan10-Aug-13 19:40
Ssntosh Chouhan10-Aug-13 19:40 
BugTypo Pin
Tiago Becerra Paolini1-Jan-13 14:01
Tiago Becerra Paolini1-Jan-13 14:01 
Generalnot so bad..but also not so good...! Pin
vaibhav201029-Feb-12 2:29
vaibhav201029-Feb-12 2:29 
Generalnot so bad..but also not so good...! Pin
vaibhav201029-Feb-12 2:29
vaibhav201029-Feb-12 2:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.