A webpage should deliver any kind of content, not just static text and images. Earlier, video/audio required plugins like Flash or QuickTime, which was inefficient and insecure.
How can we embed video/audio in a standardized, plugin-free way that works on all modern browsers?
<video> and <audio> tags
Dedicated HTML tags embed and control media natively.
<video src="my-awesome-video.mp4"></video>
Issue: Only shows the first frame. Solution: add controls attribute.
<video src="my-awesome-video.mp4" controls></video>
<video src="video.mp4" width="640" height="360" controls></video>
<video src="video.mp4" autoplay muted controls></video>
Modern browsers block autoplay with sound, use muted for it to work.
<video src="video.mp4" poster="images/video-thumbnail.jpg" controls></video>
<audio> Tag
<p>Listen to our theme song:</p> <audio src="audio/theme-song.mp3" controls></audio>
<video controls poster="images/thumbnail.jpg"> <source src="videos/my-video.webm" type="video/webm"> <source src="videos/my-video.mp4" type="video/mp4"> Sorry, your browser doesn't support embedded videos. </video>
<video controls> <source src="video.webm" type="video/webm"> <source src="video.mp4" type="video/mp4"> <track src="captions_en.vtt" kind="captions" srclang="en" label="English"> <track src="subtitles_es.vtt" kind="subtitles" srclang="es" label="Español"> </video>
<video width="320" height="240" controls> <source src="movie.mp4" type="video/mp4"> <source src="movie.ogg" type="video/ogg"> Your browser does not support the video tag. </video>
<video src="a.mp4" controls></video>
| Feature | Example 1 (<source> Method) | Example 2 (src Method) |
|---|---|---|
| Browser Compatibility | Excellent. Multiple formats. | Good, relies on single format. |
| Flexibility | High. Multiple formats possible. | Low. Only one format. |
| Simplicity | More complex. | Very simple. |
| Fallback for Old Browsers | Yes, with text. | No fallback. |
| Best Use Case | Public-facing websites. | Quick tests, internal projects. |
For public websites, prefer the <source> method. For internal or less critical projects, the direct src method is acceptable.
Entity Name:
<footer>
<p>Copyright © 2024 My Awesome Website. All Rights Reserved.</p>
</footer>
Entity Number:
<footer>
<p>Copyright © 2024 My Awesome Website. All Rights Reserved.</p>
</footer>
| Symbol | Description | Entity Name | Entity Number |
|---|---|---|---|
| © | Copyright | © | © |
| ® | Registered Trademark | ® | ® |
| ™ | Trademark | ™ | ™ |
| < | Less-than | < | < |
| > | Greater-than | > | > |
| & | Ampersand | & | & |
| " | Double Quote | " | " |
| € | Euro Sign | € | € |
Note: Use entities for < and > to display HTML code literally.