Images & Responsive Art0%

Images & Responsive Art

Beginner8 min readUpdated: 2026-09-10
Study Materials

Images & Responsive Art (Bringing Visuals to Life) 📸

Welcome to Chapter 10: Media in HTML!

As the famous saying goes: "A picture is worth a thousand words!"

Imagine reading your school Science or Social Studies textbook if it only had walls of black-and-white plain text without a single diagram of the solar system, no photos of historic monuments, and no maps of India. It would feel boring and exhausting to read!

On the web, images capture attention, explain concepts visually, and build trust.

In this lesson, you will learn:

  1. 1
    How to embed pictures using the <img> tag.
  2. 2
    Why the alt attribute is the most important image rule on the web.
  3. 3
    How to caption photos like a real textbook using <figure> and <figcaption>.
  4. 4
    How to switch images between mobile phones and computers using the modern <picture> element!

The <img> Element 🖼️

In HTML, images are embedded using the <img> tag.

Unlike paragraphs or headings, the <img> tag is an empty / void tag (it has no closing </img> tag).

HTML
<img src="robotics-lab.jpg" alt="Students building an autonomous drone in the robotics lab" width="600" height="400">

Anatomy of an <img> Tag:

Output
<img src="school-lab.jpg" alt="Students coding" width="600" height="400">
──── ─────────────────── ───────────────────── ─────────── ────────────
│ │ │ │ │
Tag Name Image Source File Alternative Text Width Height
(Path / URL) (For Screen Readers) (in pixels) (in pixels)
  1. 1
    src (Source): The file path or web URL where the image file is stored.
  2. 2
    alt (Alternative Text): A written description of what is inside the picture.
  3. 3
    width & height: The dimensions of the image in pixels.

The 3 Superpowers of the alt Attribute 🛡️

Beginners often skip writing the alt attribute because the image displays fine without it. Never do that! The alt attribute is the #1 rule of ethical web development:

  1. 1
    Accessibility for Visually Impaired Students 🎧:

Blind or low-vision students navigate websites using Screen Reader software. The software literally speaks the alt text aloud into their headphones: "Photo: Students building an autonomous drone in the robotics lab."

  1. 1
    Slow Internet / Broken Link Backup 📶:

If a student is on a slow 2G/3G mobile network or the image link breaks, the browser shows a small icon alongside your alt text so the student still knows what was supposed to be there!

  1. 1
    Search Engine Optimization (SEO) 🔍:

Google Image Search cannot "look" at pixels with human eyes; it reads your alt text to rank your school photos when people search online!


Why You MUST Always Provide width and height 📐

Have you ever visited a news website or blog on your smartphone, started reading a sentence, and suddenly &mdash; BAM! &mdash; an image popped onto the screen and the entire text jarringly jumped down 3 inches, making you lose your reading place?

That annoying jumping glitch is called Cumulative Layout Shift (CLS).

The Fix:

When you give the browser explicit width and height numbers in HTML:

HTML
<img src="annual-day.jpg" alt="School Annual Day Dance" width="800" height="450">

The browser instantly reserves an exact rectangular empty space on the screen before the image even finishes downloading! When the picture finally downloads, it slips smoothly into its pre-reserved box without moving any text!


Native Lazy Loading: Saving Mobile Internet Data 🚀

What if your school gallery has 50 high-resolution photos, but a visitor only glances at the first two at the top of the page? Downloading all 50 photos wastes their mobile internet data and slows down your website!

HTML gives you a magic attribute: loading="lazy":

HTML
<img src="sports-day-photo.jpg" alt="100m sprint race winner" width="600" height="400" loading="lazy">

With loading="lazy", the browser will NOT download the image until the user scrolls down and gets close to it! It speeds up page loading dramatically.


Semantic Photo Captions: <figure> and <figcaption> 📚

In science textbooks, you frequently see diagrams labeled like: "Figure 2.4: Cross-section of a Plant Cell".

In HTML5, we create textbook-style captions using <figure> and <figcaption>:

HTML
<figure style="border: 1px solid #CBD5E1; padding: 10px; border-radius: 8px; max-width: 500px; background-color: #F8FAFC;">
<img src="chandrayaan3.jpg" alt="Pragyan rover on lunar surface" width="480" height="300" style="border-radius: 6px;">
<figcaption style="font-size: 0.9rem; color: #475569; margin-top: 8px; text-align: center;">
<strong>Figure 1.1:</strong> The ISRO Pragyan Rover exploring the lunar South Pole.
</figcaption>
</figure>
  • <figure>: The outer container wrapping the image and its caption together.
  • <figcaption>: The caption text describing the figure.

Common Image Formats on the Web 🖼️

Which image format should you save your drawings and photos in?

FormatBest ForWhy Use It?
JPEG / JPGReal-life photographsSmall file sizes with rich millions of realistic colors.
PNGLogos, icons & graphicsSupports transparent backgrounds; sharp crisp text lines.
WebPModern web standardDeveloped by Google; 30% smaller than JPG and PNG with identical quality!
SVGVector logos & line iconsMade of math formulas, so it never gets pixelated or blurry even on giant 4K TV screens!

Responsive Art Direction: The <picture> Element 📱💻

Imagine you have a wide photograph of your school cricket team:

  • On a wide laptop screen, the landscape photo looks stunning.
  • But on a tall, narrow smartphone screen, that wide photo shrinks into a tiny, unreadable strip where you can't even see the players' faces!

Wouldn't it be amazing if your website automatically showed a wide landscape photo on laptops, but switched to a close-up cropped portrait photo on phones?

This is called Art Direction, and we do it using the HTML5 <picture> tag!

How the <picture> Element Works:

  1. 1
    The browser checks the <source media="..."> rules from top to bottom.
  2. 2
    If the user is on a phone (max-width: 600px), it loads the mobile image!
  3. 3
    If none match, it displays the fallback <img> at the bottom.

Common Beginner Mistakes (And How to Avoid Them) ⚠️

1. ⚠️ Forgetting the alt attribute

Never leave off alt="". If an image is purely decorative (like a little background sparkle), write an empty alt="" so screen readers know to ignore it safely.

2. ⚠️ Writing incorrect file extensions

File extensions are case-sensitive on many web servers! If your photo is photo.JPG and you write src="photo.jpg", the image will break on the live internet.

3. ⚠️ Distorting image proportions

If your photo is $800 \times 400$ (a 2:1 ratio), never set width="800" and height="800". It will stretch your picture vertically and make people look unnaturally tall! Always maintain the original aspect ratio.


Quick Summary

  • The <img> tag is an empty / void element that embeds images onto a webpage using the src attribute.
  • Always provide an alt attribute for screen reader accessibility, SEO, and broken-image fallbacks.
  • Always define explicit width and height to prevent Cumulative Layout Shift (CLS).
  • Add loading="lazy" to defer off-screen images and save mobile internet data.
  • Use <figure> and <figcaption> to create textbook-style captions for diagrams and photos.
  • Use the <picture> element for responsive art direction to show different image crops on smartphones vs desktops.

Practice Quiz

Test your understanding with these multiple-choice questions:

1. Which attribute specifies the file path of an image in the <img> tag?

A. href B. link C. src D. path Answer: C Explanation: src stands for Source and holds the URL or file path of the image.


2. Why is the alt attribute considered essential on all HTML images?

A. It changes the border color of the image B. It provides alternative text for screen readers and slow internet connections C. It compresses the file size automatically D. It opens the image in a new tab Answer: B Explanation: The alt attribute provides accessible alternative text read by screen readers and displayed if the image fails to load.


3. What happens if you add loading="lazy" to an image?

A. The image becomes blurry B. The image is downloaded only when the user scrolls near it C. The image animates in slow motion D. The browser waits 10 seconds before rendering Answer: B Explanation: Native lazy loading delays downloading the image until it is near the user's visible viewport, saving bandwidth.


4. Which semantic tags should be used to display an illustration accompanied by a caption?

A. <image> and <text> B. <figure> and <figcaption> C. <photo> and <caption> D. <picture> and <title> Answer: B Explanation: <figure> groups media content, and <figcaption> provides its official caption.


5. Which image format is vector-based and never loses sharpness or becomes blurry when zoomed in?

A. JPEG B. PNG C. SVG D. WebP Answer: C Explanation: SVG (Scalable Vector Graphics) is based on XML mathematical paths, so it stays pin-sharp at any resolution.


Hands-on Practice Challenge 🎯

Open VS Code and create a file named school-gallery.html.

Your Challenge:

Create a "School Science & Sports Exhibition Showcase":

  1. 1
    Featured Photo: Embed a photo using <img> with full src, descriptive alt, explicit width, height, and loading="lazy".
  2. 2
    Textbook Diagram: Create a <figure> card with an image of the Solar System or an atom, followed by a <figcaption> labeled "Figure 1: Orbital Model of the Atom".
  3. 3
    Responsive Hero Banner: Use <picture> with a mobile source (max-width: 600px) and a desktop fallback image.
  4. 4
    Test your page in your browser, resize the browser window, and observe the responsive image adaptation!

Next Up: In Topic 10.2, we will master Audio & Video in HTML5 &mdash; how to play native school podcasts, video lectures, and add accessible subtitles!

Next Lesson

Audio & Video

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Div & Span ContainersAudio & Video

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

PrevNext