Links, Images & Media
Create accessible links, write meaningful alt text, prevent layout shift on images, and pair visuals with captions using figure.
What you'll learn
- Write clear, accessible link text and safe external links
- Use alt, width, height, and loading="lazy" on images for accessibility and performance
- Group media with captions using <figure> and <figcaption>
Hyperlinks (<a>) and images (<img>) turn isolated documents into a connected, visual web. Getting their attributes right directly improves accessibility and Core Web Vitals (like Cumulative Layout Shift).
Writing Better Links
Screen-reader users often scan a page by listing all links out of context. That’s why link text should make sense on its own.
<a href="/courses/css-layout">
Explore the CSS Layout course
</a> To start learning CSS,
<a href="/courses/css-layout">click here</a>. When opening an external link in a new tab with target="_blank", always add rel="noopener noreferrer" for security.
Performant, Accessible Images
Every <img> should include:
alt: Describes the image’s purpose. Use an emptyalt=""for purely decorative images so screen readers skip them.width&height: Lets the browser reserve exact space before the image loads, preventing jarring page jumps (CLS).loading="lazy": Defers off-screen images until the user scrolls near them. (Skip lazy loading on your main above-the-fold hero image!)
Try It Yourself
Edit the SVG data image, caption, or link attributes below:
Check Your Understanding
1. What alt attribute should you use on a purely decorative background icon?
2. Why should you include width and height attributes on <img> elements?
Finished this lesson?
Your progress is saved locally in your browser, no account needed.