HTML Docs

HTML Multimedia

A guide to embedding images, audio, video, and other multimedia content in your web pages.

This guide will help you understand how to include multimedia elements like images, audio, and video in HTML. You’ll also learn how to embed content from services like YouTube and Google Maps.

HTML allows you to include various types of multimedia in your webpages. From images to videos and even embedded content, you can easily integrate rich media to enhance the user experience.

🖼️ Images

The most common way to display images is through the <img> tag. Here's an example of how to use it:

<img src="image.jpg" alt="A beautiful landscape" width="600" height="400">
  • src: Specifies the image file path.
  • alt: Provides alternative text for the image, useful for accessibility.
  • width and height: Define the dimensions of the image.

🎶 Audio

The <audio> tag allows you to embed audio files on your webpage. It supports several formats like MP3, WAV, and OGG.

Example:

<audio controls>
  <source src="audio.mp3" type="audio/mp3">
  <source src="audio.ogg" type="audio/ogg">
  Your browser does not support the audio element.
</audio>

Attributes:

  • controls: Displays play, pause, and volume control buttons.
  • autoplay: Starts playing the audio automatically when the page loads.
  • loop: Loops the audio when it ends.

Supported formats:

  • MP3
  • WAV
  • OGG

🎥 Video

Similar to the audio tag, the <video> tag is used to embed video files. You can add controls like play, pause, and volume, as well as set attributes like autoplay and loop.

Example:

<video controls width="600" height="400">
  <source src="video.mp4" type="video/mp4">
  <source src="video.webm" type="video/webm">
  <source src="video.ogv" type="video/ogv">
  Your browser does not support the video element.
</video>

Attributes:

  • controls: Displays video controls (play, pause, etc.).
  • autoplay: The video starts automatically when the page loads.
  • loop: The video will play continuously.
  • muted: Starts the video without sound.

🌐 Embed

Sometimes you may want to embed external content, such as a YouTube video or a Google Map. This can be done with the <iframe> tag.

🎬 Embedding a YouTube Video

To embed a YouTube video, use the following code:

<iframe width="560" height="315" src="https://www.youtube.com/embed/dQw4w9WgXcQ" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
  • src: The URL of the embedded content (in this case, a YouTube video).
  • frameborder: Controls the border of the iframe.
  • allowfullscreen: Allows the video to be viewed in full-screen mode.

🗺️ Embedding a Google Map

To embed a Google Map, you can use the following code:

<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3153.330809527484!2d-122.42167818468145!3d37.77492977975939!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x8085808c081c9dbd%3A0x78bb8bff3e2fc3f7!2sSan+Francisco%2C+CA!5e0!3m2!1sen!2sus!4v1614845371760!5m2!1sen!2sus" width="600" height="450" frameborder="0" style="border:0;" allowfullscreen="" aria-hidden="false" tabindex="0"></iframe>
  • src: The URL to the embedded map.
  • frameborder: Sets the border of the embedded map.
  • allowfullscreen: Allows the map to be viewed in fullscreen mode.

🧪 Try Yourself

import "./styles.css";

document.getElementById("app").innerHTML = `
<h1>Hello world</h1>
`;

✅ Conclusion

With HTML, adding multimedia elements like images, audio, and video is straightforward. You can also embed external content like YouTube videos and Google Maps using iframes. These features will enhance the interactivity and richness of your webpage.

Pro Tip: Always provide alternative content (like text) in case multimedia elements do not load, and make sure that your media files are optimized for faster loading times.

📚 Resources

On this page