Lab 03: Box Model & Layout

🎯 Objective

Learn to create hyperlinks with <a> and embed images with <img>, including relative/absolute paths, target attributes, and accessibility best practices.

πŸ“š Background

Links and images are two of the most fundamental HTML elements. The <a> (anchor) tag creates clickable links, while <img> embeds images. Both require attributes to function correctly β€” href for links and src/alt for images.

⏱️ Estimated Time

30 minutes

πŸ“‹ Prerequisites

  • Labs 1–2 completed

πŸ› οΈ Tools Used

  • Python 3

  • Web browser

πŸ”¬ Lab Instructions

Step 1: Create the lab file

Step 2: Create a sample image for testing

πŸ’‘ Always add rel="noopener noreferrer" with target="_blank" to prevent security vulnerabilities.

Step 4: Add the images section

πŸ’‘ Never omit alt. Use empty alt="" for purely decorative images so screen readers skip them.

Step 6: Add an anchor at the top

Step 7: Validate HTML

πŸ“Έ Verified Output:

Open http://localhost:8080/lab03-links-images.html. Click each link to verify they work.

πŸ“Έ Verified Output:

  • Internal anchor links jump to the correct section

  • download attribute triggers file download

  • target="_blank" opens external links in a new tab

βœ… Verification

🚨 Common Mistakes

  • Missing alt attribute β€” Required for accessibility; screen readers need it

  • Using target="_blank" without rel="noopener" β€” Security vulnerability (tab nabbing)

  • Absolute paths for local files β€” Use relative paths; absolute paths break when deployed

  • Empty link text β€” <a href="...">Click here</a> is bad; describe the destination

  • Missing width/height on images β€” Causes layout shift (CLS) as page loads

πŸ“ Summary

You learned:

  • <a href=""> for links with absolute, relative, anchor, email, and phone URLs

  • target="_blank" with rel="noopener noreferrer" for safe external links

  • <img src="" alt=""> with proper alt text for accessibility

  • loading="lazy" for performance

  • <figure> and <figcaption> for semantic image captions

  • download attribute for downloadable files

πŸ”— Further Reading

Last updated