Embedding Media in HTML Images Video & Audio
Introduction
Embedding media in HTML means adding images, videos, and audio files directly into a web page so users can see, watch, or listen to content without leaving the site. Media elements make websites more engaging, interactive, and visually appealing.
For example, a student in Lahore building a school project website might want to show images of historical places in Pakistan, a video explaining a science experiment, or an audio recording of a national song. Instead of just displaying plain text, HTML media elements allow developers to include rich content.
In HTML, media is embedded using special tags such as:
- HTML images using the img tag
- HTML video using the video tag
- HTML audio using the audio tag html
These elements are part of modern HTML5, which makes adding multimedia simple and browser-friendly.
For Pakistani students learning web development, understanding how to embed media is important because:
- It helps create modern websites
- It improves user experience
- It is essential for portfolio projects
- It is widely used in blogs, e-learning platforms, and business websites
In this tutorial, you will learn how to use HTML images, HTML video, and HTML audio, along with best practices and real-world examples.
Prerequisites
Before starting this tutorial, you should have basic knowledge of the following:
- Basic HTML structure
- Understanding of HTML tags and attributes
- How to create a simple HTML web page
- Basic knowledge of text editors like VS Code or Notepad++
If you are new to HTML, it is recommended to first read:
- HTML Basics: Introduction to Web Development
- Understanding HTML Elements and Tags
- HTML Page Structure Explained
These tutorials will help you understand the concepts used in this guide.
Core Concepts & Explanation
Understanding HTML Images and the img Tag
Images are the most commonly used media element on websites. In HTML, images are added using the <img> tag.
Unlike most HTML elements, the img tag does not have a closing tag because it is self-closing.
Basic syntax:
<img src="image.jpg" alt="Description of image">
Important attributes:
| Attribute | Description |
|---|---|
| src | Path to the image file |
| alt | Alternative text for accessibility |
| width | Width of the image |
| height | Height of the image |
Example:
<img src="badshahi-mosque.jpg" alt="Badshahi Mosque Lahore" width="500">
Explanation:
src="badshahi-mosque.jpg"→ Tells the browser where the image file is located.alt="Badshahi Mosque Lahore"→ Displays text if the image cannot load.width="500"→ Sets the width of the image.
The alt attribute is very important because it helps:
- Screen readers for visually impaired users
- Search engines understand the image
- Display text if the image fails to load
Example for Pakistani website:
A tourism website about Lahore might display images of:
- Badshahi Mosque
- Minar-e-Pakistan
- Lahore Fort
Each image can be embedded using the img tag.
Embedding Video Using the video Tag
HTML5 introduced the video tag, which allows developers to embed videos directly into web pages without using external plugins like Flash.
Basic syntax:
<video controls>
<source src="video.mp4" type="video/mp4">
</video>
Important attributes:
| Attribute | Description |
|---|---|
| controls | Shows play, pause, and volume controls |
| autoplay | Starts video automatically |
| loop | Replays the video continuously |
| muted | Mutes the sound |
Example:
<video width="600" controls>
<source src="science-experiment.mp4" type="video/mp4">
</video>
Explanation:
<video>→ Main container for the videowidth="600"→ Sets video widthcontrols→ Adds play/pause buttons<source>→ Specifies the video filetype="video/mp4"→ Defines the video format
For example, Ali, a student from Islamabad, could create a website explaining physics experiments and embed demonstration videos.
Adding Audio Using the audio Tag
The audio tag html allows developers to embed sound files such as music, podcasts, or recordings.
Basic syntax:
<audio controls>
<source src="audio.mp3" type="audio/mpeg">
</audio>
Example:
<audio controls>
<source src="national-anthem.mp3" type="audio/mpeg">
</audio>
Explanation:
<audio>→ Defines an audio playercontrols→ Displays play/pause buttons<source>→ Specifies the audio filetype="audio/mpeg"→ Indicates file format
For example, a website about Pakistani culture might include audio recordings of:
- National songs
- Poetry recitations
- Urdu storytelling

Practical Code Examples
Example 1: Creating a Simple Media Web Page
Here is a basic HTML page containing an image, a video, and audio.
<!DOCTYPE html>
<html>
<head>
<title>My Media Page</title>
</head>
<body>
<h1>Welcome to My Media Website</h1>
<h2>Image Example</h2>
<img src="lahore-fort.jpg" alt="Lahore Fort" width="500">
<h2>Video Example</h2>
<video width="500" controls>
<source src="tour-lahore.mp4" type="video/mp4">
</video>
<h2>Audio Example</h2>
<audio controls>
<source src="pakistan-song.mp3" type="audio/mpeg">
</audio>
</body>
</html>
Line-by-line explanation:
<!DOCTYPE html>→ Defines the document as HTML5.<html>→ Root element of the web page.<head>→ Contains metadata and page title.<title>→ The page title shown in browser tabs.<body>→ Contains visible page content.<h1>→ Main heading of the page.<img>→ Displays an image.<video>→ Embeds a video player.<audio>→ Embeds an audio player.<source>→ Specifies the media file location.
This example demonstrates HTML images, HTML video, and HTML audio in one page.
Example 2: Real-World Application (Student Portfolio)
Imagine Fatima, a student from Karachi, creating a personal portfolio website.
She wants to show:
- Her project image
- A demo video
- A recorded explanation
<section>
<h2>My Web Development Project</h2>
<img src="website-project.png" alt="My website project screenshot" width="600">
<video width="600" controls>
<source src="project-demo.mp4" type="video/mp4">
</video>
<audio controls>
<source src="project-explanation.mp3" type="audio/mpeg">
</audio>
</section>
Explanation:
<section>→ Groups related content.<h2>→ Project title.<img>→ Shows a screenshot of the project.<video>→ Displays a demo video.<audio>→ Allows visitors to hear the explanation.
This approach is commonly used in portfolio websites and online courses.

Common Mistakes & How to Avoid Them
Mistake 1: Forgetting the alt Attribute in Images
Many beginners forget to add alt text.
Incorrect:
<img src="karachi.jpg">
Correct:
<img src="karachi.jpg" alt="Karachi city skyline">
Why it matters:
- Improves accessibility
- Helps SEO
- Displays text if the image fails to load
Mistake 2: Using Unsupported Media Formats
Browsers support limited formats.
Common supported formats:
Video
- MP4
- WebM
Audio
- MP3
- WAV
- OGG
Incorrect:
<video>
<source src="video.mov">
</video>
Correct:
<video controls>
<source src="video.mp4" type="video/mp4">
</video>
Using supported formats ensures the media works across browsers.
Practice Exercises
Exercise 1: Display an Image
Problem:
Create a webpage that displays an image of Minar-e-Pakistan.
Solution:
<img src="minar-e-pakistan.jpg" alt="Minar e Pakistan" width="500">
Explanation:
src→ Image file location.alt→ Image description.width→ Sets image size.
Exercise 2: Add a Video Player
Problem:
Embed a study tutorial video on a webpage.
Solution:
<video width="600" controls>
<source src="html-tutorial.mp4" type="video/mp4">
</video>
Explanation:
<video>→ Creates video container.controls→ Adds play/pause buttons.<source>→ Defines video file.
Frequently Asked Questions
What is the HTML img tag?
The img tag is used to display images on a webpage. It requires the src attribute to specify the image location and the alt attribute to describe the image.
How do I add video in HTML?
You can add video using the video tag. Inside the video element, use the <source> tag to define the video file and format.
What is the HTML audio tag used for?
The audio tag html allows developers to embed sound files such as music, podcasts, or voice recordings directly into a webpage.
Why is the alt attribute important?
The alt attribute improves accessibility for screen readers and displays text if the image fails to load. It also helps search engines understand the image content.
Which formats are supported for HTML media?
Common supported formats include MP4 and WebM for video, and MP3, WAV, and OGG for audio. These formats work in most modern browsers.
Summary & Key Takeaways
- HTML images are added using the img tag.
- HTML video is embedded using the video tag.
- HTML audio is embedded using the audio tag html.
- Always include the alt attribute for images.
- Use supported formats such as MP4 and MP3.
- Media elements make websites more interactive and engaging.
Next Steps & Related Tutorials
Now that you understand embedding media in HTML, you should continue learning more HTML concepts.
Recommended tutorials on theiqra.edu.pk:
- Learn how to structure pages with HTML Semantic Elements
- Understand how to organize information using HTML Tables
- Improve layout design with HTML Div and Section Elements
- Build responsive pages using HTML and CSS Basics
Mastering these topics will help you create professional websites and web applications.
Test Your Python Knowledge!
Finished reading? Take a quick quiz to see how much you've learned from this tutorial.