Media

Embed audio and video content directly in the browser.

Modern websites are much more than just text and images. Many websites include videos, music, podcasts, animations, and other types of media to create a richer user experience. In HTML, these types of content are called multimedia.

Multimedia helps make websites more engaging, interactive, and informative. For example, a learning website may use videos to explain concepts, while a music website may allow users to play songs directly on the page.

What Is Multimedia?

Multimedia refers to content that combines different types of media, such as:

  • Audio
  • Video
  • Images
  • Animations

HTML provides special elements that allow developers to display and control multimedia content directly within a webpage.

Why Is Multimedia Important?

Multimedia improves the user experience by making content easier to understand and more enjoyable to consume.

For example:

  • A cooking website can include recipe videos.
  • A news website can publish video reports.
  • An online course can provide recorded lessons.
  • A podcast website can offer audio playback.

Instead of downloading files separately, users can interact with media directly in their browser.

Adding Audio to a Webpage

HTML uses the audio element to play sound files.

html
<audio controls>
    <source src="song.mp3" type="audio/mpeg">
</audio>

The controls attribute displays built-in audio controls such as:

  • Play
  • Pause
  • Volume

Users can control playback without needing additional software.

Adding Video to a Webpage

HTML uses the video element to display videos.

html
<video width="400" controls>
    <source src="video.mp4" type="video/mp4">
</video>

The browser displays a video player with controls for:

  • Play
  • Pause
  • Full screen
  • Volume

The width attribute controls the video's size.

Understanding the <source> Element

The source element specifies the media file location.

html
<source src="movie.mp4" type="video/mp4">

This tells the browser:

  • Where the file is located.
  • What file format is being used.

Multiple source elements can be provided for better browser compatibility.

Real-World Example

Imagine an online learning website.

html
<h2>HTML Tutorial</h2>

<video controls width="600">
    <source src="html-lesson.mp4" type="video/mp4">
</video>

Students can watch lessons directly on the webpage without downloading the video.

Similarly, a podcast website might use:

html
<audio controls>
    <source src="podcast.mp3" type="audio/mpeg">
</audio>

This allows visitors to listen to episodes online.

Common Multimedia Formats

Audio Formats

  • MP3
  • WAV
  • OGG

Video Formats

  • MP4
  • WebM
  • OGG

Among these, MP4 and MP3 are the most widely supported formats.

Best Practices

When working with multimedia:

  • Use widely supported file formats.
  • Keep media files optimized for faster loading.
  • Provide playback controls for users.
  • Avoid autoplay when possible.
  • Include alternative content when media cannot be played.

These practices help improve accessibility and user experience.

Summary

HTML multimedia allows websites to display audio and video content directly in the browser. The audio element is used for sound, while the video element is used for video playback. Together with the source element, these tags make it easy to create interactive and engaging websites. Multimedia is widely used in online learning platforms, entertainment websites, podcasts, and modern web applications.

Let's learn with DevBrainBox AI