So far, we have learned how to add text, headings, lists, and links to a webpage.
In this module, we will learn how to add pictures, music, and videos to make our webpages more fun and exciting.
An image is a picture displayed on a webpage. Pictures help visitors understand information more easily.
For example, instead of describing a dog, you can simply show a picture of a dog.
Think of a webpage as a storybook. Images are the colorful illustrations that make the story interesting.
HTML uses the <img> tag to display images.
<img src="dog.jpg" alt="A cute dog">
The browser needs to know where the picture is saved. The location of the image is called the image path.
<img src="football.jpg" alt="Football">
This means the image named football.jpg is saved in the same folder as the HTML file.
Imagine sending a friend to your classroom. You must tell them exactly where it is. The image path tells the browser where to find the picture.
We can make images bigger or smaller using width and height.
<img src="dog.jpg"
alt="Dog"
width="200"
height="150">
Width controls how wide the image is. Height controls how tall the image is.
The alt attribute describes the image.
<img src="cat.jpg"
alt="A white cat sleeping">
If the image cannot be displayed, the browser shows the description.
It also helps people who use screen readers understand the picture.
Audio allows visitors to listen to sounds or music.
<audio controls>
<source src="song.mp3">
</audio>
The controls attribute creates play and pause buttons.
Imagine adding your favorite song to your webpage. Visitors can listen to it while reading.
Videos can also be displayed on a webpage.
<video width="300" controls>
<source src="video.mp4">
</video>
Visitors can play, pause, and watch the video.
Imagine creating a webpage about football and adding a video showing your favorite football match.
<!DOCTYPE html>
<html>
<head>
<title>My Favorite Animal</title>
</head>
<body>
<h1>My Favorite Animal</h1>
<p>I love dogs.</p>
<img src="dog.jpg"
alt="A happy dog"
width="250">
</body>
</html>
Fill in the blanks:
Create a webpage called mypet.html.
Include:
Fix the missing parts below:
<img _____="cat.jpg"
_____="A cute cat"
width="200">
What attributes are missing?
Create a webpage called myfavoriteanimal.html.
Add:
Create a webpage about your favorite football team, cartoon character, or superhero.
Include: