How to embed audio files in html?

View Discussion

Improve Article

Save Article

  • Read
  • Discuss
  • View Discussion

    Improve Article

    Save Article

    Since the release of HTML5, audio can be added to webpages using the <audio> tag. Previously audio could be only played on webpages using web plugins like Flash. The <audio> tag is an inline element which is used to embed sound files into a web page. It is a very useful tag if you want to add audio such as songs, interviews, etc on your webpage.

    Syntax:

    <audio> <source src="sample.mp3" type="audio/mpeg"> </audio>

    Example 1:

    HTML

    <!DOCTYPE html>

    <html>

    <body>

        <h2 style="color:green;">

            GeeksforGeeks

        </h2>

        <h3>

            How to embed audio in a HTML document?

        </h3>

        <audio controls>

            <source src="test.mp3" type="audio/mp3">

            <source src="test.ogg" type="audio/ogg">

        </audio>

    </body>

    </html>

    Output:

    How to embed audio files in html?

    Example 2: In this example, audio will play automatically after loading the web page.

    HTML

    <!DOCTYPE html>

    <html>

    <body>

        <h2 style="color:green;">

            GeeksforGeeks

        </h2>

        <h3>

            How to embed audio in a HTML document?

        </h3>

        <audio controls autoplay>

            <source src="test.mp3" type="audio/mp3">

            <source src="test.ogg" type="audio/ogg">

        </audio>

    </body>

    </html>

    Output:


    How do I embed an audio file on my website?

    An easy way to embed audio on a website is by using a sound hosting site, such as SoundCloud or Mixcloud. All you need to do is upload the file and receive an HTML embed code. Then copy and paste the embed code into the web page's code or WYSIWYG site editor. This works for most CMS platforms and website builders.

    How do I embed audio and video in HTML?

    The <vid eo> element allows us to embed video files into an HTML, very similar to the way images are embedded. Attributes we can include are: src This attribute stands for the source, which is very similar to the src attribute used in the image element. We will add the link to a video file in the src attribute.

    Which tag is used for inserting audio files is HTML?

    <audio>: The Embed Audio element. The <audio> HTML element is used to embed sound content in documents.