Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Embedding Audio Files in HTML | Images and Media
HTML Essentials

book
Embedding Audio Files in HTML

In HTML, we can embed audio and video content directly into the web pages using the <audio> and <video> tags, respectively. Let's discuss embedding audio first:

Embedding Audio

The <audio> tag embeds audio content into an HTML document. It allows you to play audio files directly within the browser.

Audio Attributes

  • controls: Adds standard audio controls, such as play, pause, and volume adjustment, to the player;

  • autoplay: Specifies whether the audio should start playing automatically when the page loads;

  • loop: Specifies whether the audio should loop continuously.

Example:

html
<audio controls autoplay loop>
<!-- Some other tags -->
</audio>

You may have noticed that we have only specified the characteristics of the audio player, but we have not mentioned where the audio is coming from. We need the <source> tag.

Source

The <source> tag is used inside the <audio> tag to specify the URL of the audio file and its attributes. We can use the src attribute to specify the URL of the audio file and the type attribute to specify the MIME type of the audio file.
Example:

html
<audio controls autoplay loop>
<source src="audio-url.mp3" type="audio/mpeg" />
<source src="audio-url.ogg" type="audio/ogg" />
Your browser does not support the audio element.
</audio>

In the example above:

  • The <audio> tag includes attributes such as controls, autoplay, and loop;

  • The <source> tags specify the source URLs of the audio files and their MIME types;

  • If the browser does not support the <audio> tag or the specified audio formats, the alternative text Your browser does not support the audio element. is displayed.

html

index.html

copy
<!DOCTYPE html>
<html>
<head>
<title>Audio</title>
<meta charset="UTF-8" />
</head>
<body>
<audio controls loop>
<source
src="https://codefinity-content-media-v2.s3.eu-west-1.amazonaws.com/courses/392f24ac-0126-4c34-a28a-f2f26d12196b/section-3/in-the-forest-audio-example.mp3"
type="audio/mpeg"
/>
Your browser does not support the audio element.
</audio>
</body>
</html>

Video Tutorial

1. Which tag is used to embed audio content into an HTML document?

2. Why is it recommended to provide the audio in multiple formats?

question mark

Which tag is used to embed audio content into an HTML document?

Select the correct answer

question mark

Why is it recommended to provide the audio in multiple formats?

Select the correct answer

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 3. Hoofdstuk 3

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

We use cookies to make your experience better!
some-alt