Computer Science Grade 6 20 min

Adding Images to Your Webpage: The `<img>` Tag

Learn to embed images into your webpage using the `<img>` tag and image sources.

Tutorial Preview

1

Introduction & Learning Objectives

Learning Objectives Explain the purpose of the `&lt;img&gt;` tag in HTML. Write the correct HTML code to display an image on a webpage. Use the `src` attribute to link to an image file. Use the `alt` attribute to provide alternative text for an image. Use the `width` and `height` attributes to change the size of an image. Identify the difference between a local image file path and an online image URL. Have you ever wondered how your favorite websites show pictures of funny cats or cool video game characters? 🖼️ Let&#039;s learn the secret code to make our own webpages more colorful and fun! In this lesson, you will learn how to use a special HTML tag called the `&lt;img&gt;` tag. This tag lets you add pictures to your projects, making them look amazing. We will learn how to...
2

Key Concepts & Vocabulary

TermDefinitionExample &lt;img&gt; TagA special HTML instruction that tells the browser to display an image on the page. It&#039;s a self-closing tag, meaning it doesn&#039;t need a separate closing tag like &lt;/p&gt;.&lt;img&gt; AttributeExtra information you add inside an HTML tag to change how it works or what it does. Attributes are made of a name and a value, like name=&quot;value&quot;.In `&lt;img src=&quot;dog.jpg&quot;&gt;`, `src` is the attribute name and `&quot;dog.jpg&quot;` is the attribute value. src AttributeThe &#039;source&#039; attribute. It tells the `&lt;img&gt;` tag the location or file name of the picture you want to show. This is the most important attribute for an image.src=&quot;images/robot.png&quot; alt AttributeThe &#039;alternative text&#039; attribute. It prov...
3

Core Syntax & Patterns

Basic Image Tag Syntax &lt;img src=&quot;file_name.extension&quot; alt=&quot;description of image&quot;&gt; This is the fundamental structure for adding an image. You must always include the `src` (source) attribute to tell the browser which image to load and the `alt` (alternative text) attribute for accessibility. Image Sizing Attributes &lt;img src=&quot;...&quot; alt=&quot;...&quot; width=&quot;100&quot; height=&quot;150&quot;&gt; Use the `width` and `height` attributes to control the size of your image. The values are numbers that represent pixels (tiny dots on your screen). Linking to Online Images &lt;img src=&quot;https://www.example.com/images/photo.jpg&quot; alt=&quot;...&quot;&gt; Instead of a local file name, you can use a full web address (URL) in the `s...

4 more steps in this tutorial

Sign up free to access the complete tutorial with worked examples and practice.

Sign Up Free to Continue

Sample Practice Questions

Challenging
For a pet adoption website, which of the following is the BEST `alt` text for a picture of a small, brown, fluffy cat napping in a sunbeam?
A.alt="image"
B.alt="A small, brown, fluffy cat sleeping in a sunbeam"
C.alt="cat.png"
D.alt="This is a picture of a cat that you can adopt from our store. It is brown and fluffy and it is sleeping. Click here for more details."
Challenging
A very large, high-resolution photo (`mountains.jpg`, 10MB file size) is added to a page with `<img src="mountains.jpg" width="150">`. The page loads very slowly. Why?
A.The browser has to download the full 10MB file, even though it displays it smaller
B.The `width` attribute is too small for a large file
C.The `alt` text is missing, which slows down loading
D.JPG files are always slow to load
Challenging
How can you make an image of a button also work as a clickable link to `https://example.com`?
A.<img src="button.png" href="https://example.com">
B.<link href="https://example.com"><img src="button.png"></link>
C.<img src="button.png" link="https://example.com">
D.<a href="https://example.com"><img src="button.png" alt="Clickable button"></a>

Want to practice and check your answers?

Sign up to access all questions with instant feedback, explanations, and progress tracking.

Start Practicing Free

More from Web Development Basics

Ready to find your learning gaps?

Take a free diagnostic test and get a personalized learning plan in minutes.