How to Add Images, Videos & Audio in HTML
How to Add Images, Videos & Audio in HTML (Complete Beginner Guide With Examples)
When you visit a website, you see:
✅ pictures
✅ background images
✅ product photos
✅ YouTube videos
✅ music players
✅ audio instructions
All of these are added using HTML media tags.
In this lesson, I will teach you, step-by-step:
-
How to add images in HTML
-
How to add videos in HTML
-
How to add audio in HTML
-
Important attributes
-
Best practices
-
Common mistakes
By the end of this topic, you will be able to make your webpage look attractive and interactive.
Let’s begin like a teacher, slowly and clearly.
What Are Media Elements in HTML?
Media elements are HTML tags that allow us to display visual and audio content on a webpage.
The three main tags are:
| Media | HTML Tag |
|---|---|
| Image | <img> |
| Video | <video> |
| Audio | <audio> |
How to Add Images in HTML
We use the <img> tag to show images.
๐ Important point:
The <img> tag is self-closing, meaning it does NOT need </img>.
Basic Image Example
<img src="image.jpg" alt="Sample Image">
Explanation:
-
src→ location of image -
alt→ text shown if image fails to load
File Types Supported
HTML supports:
-
JPG / JPEG (photos)
-
PNG (transparent images)
-
GIF (animations)
-
SVG (icons, logos)
-
WebP (modern, small size)
Adding Image With Width & Height
<img src="flower.jpg" alt="Flower" width="300" height="200">
Adding Image From Internet (URL)
<img src="https://example.com/pic.jpg" alt="Online Image">
Making Image Clickable
<a href="https://google.com">
<img src="logo.png" alt="Google Logo">
</a>
This creates a linked image, useful for advertisements and banners.
Best Practices for Images (Teacher Tips)
✔ Always use alt text
✔ Use compressed images for faster loading
✔ Use meaningful filenames
✔ Avoid very large images
✔ Prefer .webp for performance
How to Add Videos in HTML
To add videos, we use the <video> tag.
Example:
<video src="movie.mp4" controls></video>
Important Attributes
| Attribute | Meaning |
|---|---|
controls |
Shows play, pause buttons |
autoplay |
Starts automatically |
loop |
Repeats video |
muted |
Starts muted |
width |
Video width |
Full Video Example
<video width="400" controls>
<source src="video.mp4" type="video/mp4">
</video>
Multiple Sources (Best Practice)
Different browsers support different video formats.
So we add multiple sources:
<video controls>
<source src="video.mp4" type="video/mp4">
<source src="video.webm" type="video/webm">
</video>
Autoplay + Loop Example
<video src="clip.mp4" autoplay loop muted></video>
๐ Many browsers block autoplay unless muted, so always include muted.
How to Add Audio in HTML
To play sound, music, or voice recordings, we use the <audio> tag.
Basic Audio Example
<audio src="song.mp3" controls></audio>
Audio With Multiple Sources
<audio controls>
<source src="sound.mp3" type="audio/mpeg">
<source src="sound.ogg" type="audio/ogg">
</audio>
Autoplay Audio
<audio src="intro.mp3" autoplay muted></audio>
๐ Note: Browsers block autoplay audio with sound.
So add muted or let user click play.
Complete HTML Example (Teacher Style)
This example includes:
✅ Image
✅ Video
✅ Audio
<!DOCTYPE html>
<html>
<head>
<title>Media Example</title>
</head>
<body>
<h1>HTML Media Demo</h1>
<h2>Image Example</h2>
<img src="flower.jpg" alt="Beautiful Flower" width="300">
<h2>Video Example</h2>
<video width="400" controls>
<source src="video.mp4" type="video/mp4">
</video>
<h2>Audio Example</h2>
<audio controls>
<source src="music.mp3" type="audio/mpeg">
</audio>
</body>
</html>
Common Mistakes Students Make
❌ Wrong file path
❌ Missing alt text
❌ Forgetting controls
❌ Very large media files
❌ Unsupported formats
Best Practices (Teacher Notes)
✔ Always include controls
✔ Use compressed files
✔ Use alt text for SEO
✔ Add multiple sources for compatibility
✔ Store media in separate folders
Example project structure:
project/
images/
videos/
audio/
index.html
Why is Media Important in Web Design?
Because media:
✅ makes websites attractive
✅ improves user experience
✅ helps learning
✅ increases engagement
✅ supports marketing
Conclusion
Now you have learned:
-
How to add images using
<img> -
How to add videos using
<video> -
How to add audio using
<audio> -
Important attributes
-
Best practices
-
Full HTML example
With this knowledge, you can create:
✔ photo galleries
✔ music players
✔ video tutorials
✔ banners and ads
✔ product showcases
.png)
Comments
Post a Comment