Media on the page
There are special elements for media on the page. We are going to show you how to add audio and video and how to embed YouTube on a webpage.
Adding an audio player to a page is very simple:
<!DOCTYPE html>
<html>
<body>
<audio controls>
<source src="sound.ogg" type="audio/ogg">
<source src="sound.mp3" type="audio/mpeg">
</audio>
</body>
</html>
You specify the controls
attribute if you want the user to be able to control pause and play and the volume. If you want it to start automatically, you'll have to add the attribute autoplay
. With the source element, you specify the audio files that can be played. The browser will choose only one and will choose the first one (from top to bottom) that it supports.
Adding a video to a webpage is very similar to adding audio. Here's how to do it:
<video width="1024"...