Course contentsShow
← Web Development
Lesson 74 of 2,9822. HTML FundamentalsFree lesson

Images: src, alt, and Accessibility

Embed images with <img>, write effective alt text, and handle decorative images.

Images: src, alt, and Accessibility

What you'll learn: How to properly embed images in your webpage while making them accessible to everyone.

The Core Concept

Images bring your webpage to life, but unlike text, they need special consideration for users who can't see them. The <img> element adds images to your HTML using two essential attributes: src (the image location) and alt (a text description).

Think of alt text like a radio broadcast describing a photograph: if someone can't see the picture, they should still understand what's there.

The <img> Element Syntax

<img src="puppy.jpg" alt="A golden retriever puppy playing with a tennis ball">

The <img> element is self-closing (no closing tag needed). The src attribute tells the browser where to find the image file, and the alt attribute provides a text alternative.

Writing Effective Alt Text

For meaningful images, describe what's important about the image in context:

<img src="ceo.jpg" alt="Maria Santos, CEO, speaking at the conference">

For decorative images (purely visual, no information value), use an empty alt attribute:

<img src="decorative-border.png" alt="">

The empty alt="" tells screen readers to skip the image entirely, preventing unnecessary interruptions. Never omit the alt attribute completely—that causes screen readers to announce the filename instead.

Why This Matters

Screen readers announce alt text to blind users. Search engines use it to understand your images. When images fail to load, browsers display the alt text. You're not just adding images—you're ensuring everyone can access your content regardless of ability or connection speed.

Key Takeaway: Always use <img> with both src and alt attributes; write descriptive alt text for meaningful images and use empty alt (alt="") for purely decorative ones to ensure accessibility.