HTML - Audio

HTML Audio

In this tutorial, I will be showing you how to add audio file to your HTML web page.

Audio

The <audio> element is used to add audio file to your HTML web page.

  • The <audio> element cannot work alone; it works together with the <source> element.
  • The <source> element takes two major attributes:
    • src - specifies the URL (address/location) of the audio file
    • type - specifies the audio format type

<audio> Attributes

Below are some of the majorly used <audio> attributes.

CONTROLS

The controls attribute is used to add controls such as: play, pause and volume

AUTOPLAY

The autoplay attribute is used to play the audio file automatically as soon as the web page loads up.

MUTED

The muted attribute is used to turn OFF the volume of the audio file when it automatically starts playing. This attribute is often used together with the autoplay attribute.

LOOP

The loop attribute is used to set the audio to start over again (from the beginning) every time it ends.


note
NOTE:

<audio> element doesn't support the poster, width and height attributes.


ADVERTISEMENTS

LEARNING IS A CONTINOUS PROCESS - PRACTICE MAKES PERFECT