Adding Audio to a Webpage

To add audio to a webpage, use the HTML audio element. This element allows you to embed sound files like music, podcasts, or sound effects directly into your document.

The audio element is the modern way to handle sound on the web, replacing older methods (like using the embed tag) that required browser plugins.

The Basic Syntax

In its simplest form, you can add an audio player like this:

Key Attributes

Interactive Example

Below is a working example of an audio player on a webpage:

View Output Full Screen Preview

Providing Multiple Formats

Not all browsers support every audio format. To ensure your audio plays for as many visitors as possible, you can provide multiple versions of your audio file using the source element:

In this case, the browser will choose the first format that it supports.