Fatskills
Practice. Master. Repeat.
Study Guide: Web-Design HTML-Images Images img src alt width height figure figcaption
Source: https://www.fatskills.com/web-designing/chapter/web-design-html-images-images-img-src-alt-width-height-figure-figcaption

Web-Design HTML-Images Images img src alt width height figure figcaption

By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.

⏱️ ~5 min read

What This Is and Why It Matters

Images are fundamental to web design, enhancing user experience and conveying information visually. This topic covers HTML elements and attributes used to include and manage images on web pages: img, src, alt, width, height, figure, and figcaption. Mastering these elements is crucial for creating accessible, responsive, and visually appealing websites. Incorrect usage can lead to broken images, poor accessibility, and a subpar user experience. For instance, neglecting the alt attribute can make your website inaccessible to visually impaired users relying on screen readers.

Core Knowledge (What You Must Internalize)

  • img: The HTML element used to embed images in a web page. (Why this matters: It's the backbone of visual content on the web.)
  • src: Attribute specifying the path to the image file. (Why this matters: It tells the browser where to find the image.)
  • alt: Attribute providing alternative text for the image. (Why this matters: It improves accessibility and SEO.)
  • width and height: Attributes defining the image's dimensions. (Why this matters: They help maintain layout consistency and improve loading performance.)
  • figure: HTML element used to group media content with a caption. (Why this matters: It semantically groups images with captions.)
  • figcaption: HTML element used to provide a caption for a figure. (Why this matters: It enhances the context and accessibility of images.)

Step‑by‑Step Deep Dive

  1. Embed an Image
  2. Use the img element.
  3. Underlying principle: The img tag is self-closing and requires the src attribute.
  4. Example: <img src="image.jpg">
  5. ⚠️ Common pitfall: Forgetting the src attribute will result in a broken image.

  6. Add Alternative Text

  7. Use the alt attribute within the img element.
  8. Underlying principle: The alt text describes the image for screen readers and search engines.
  9. Example: <img src="image.jpg" alt="A beautiful sunset">
  10. ⚠️ Common pitfall: Leaving the alt attribute empty or using irrelevant text.

  11. Specify Image Dimensions

  12. Use the width and height attributes.
  13. Underlying principle: Defining dimensions helps the browser allocate space before the image loads.
  14. Example: <img src="image.jpg" alt="A beautiful sunset" width="300" height="200">
  15. ⚠️ Common pitfall: Using incorrect dimensions can distort the image.

  16. Group Images with Captions

  17. Use the figure and figcaption elements.
  18. Underlying principle: figure semantically groups media content, and figcaption provides context.
  19. Example:
    html
    <figure>
    <img src="image.jpg" alt="A beautiful sunset">
    <figcaption>A beautiful sunset over the mountains.</figcaption>
    </figure>
  20. ⚠️ Common pitfall: Using figcaption outside of a figure element.

How Experts Think About This Topic

Experts view images as integral to both the visual and semantic structure of a web page. They prioritize accessibility and performance, using alt text thoughtfully and optimizing image dimensions. They also leverage figure and figcaption to enhance the semantic meaning and context of images.

Common Mistakes (Even Smart People Make)

  1. The mistake: Forgetting the alt attribute.
  2. Why it's wrong: It makes the image inaccessible to screen readers.
  3. How to avoid: Always include a descriptive alt text.
  4. Exam trap: Questions about accessibility will often focus on the alt attribute.

  5. The mistake: Using incorrect image dimensions.

  6. Why it's wrong: It can distort the image and affect the layout.
  7. How to avoid: Verify the actual dimensions of the image file.
  8. Exam trap: Questions about image rendering and layout issues.

  9. The mistake: Not using figure and figcaption together.

  10. Why it's wrong: It breaks the semantic relationship between the image and its caption.
  11. How to avoid: Always nest figcaption within figure.
  12. Exam trap: Questions about semantic HTML and accessibility.

  13. The mistake: Using irrelevant alt text.

  14. Why it's wrong: It confuses screen readers and search engines.
  15. How to avoid: Use descriptive and relevant alt text.
  16. Exam trap: Questions about SEO and accessibility best practices.

Practice with Real Scenarios

Scenario: You are designing a blog post about travel destinations.
Question: How would you include an image of a famous landmark with a caption? Solution:
1. Use the img element with the src attribute pointing to the image file.
2. Add a descriptive alt text.
3. Wrap the image in a figure element and add a figcaption.
Answer:


<figure>
  <img src="landmark.jpg" alt="The Eiffel Tower at sunset">
  <figcaption>The Eiffel Tower at sunset in Paris, France.</figcaption>
</figure>

Why it works: This structure ensures the image is accessible, semantically correct, and visually appealing with a caption.

Scenario: You need to optimize an image for a responsive design.
Question: How would you specify the dimensions? Solution:
1. Use the width and height attributes to define the image size.
2. Confirm the dimensions match the actual image file.
Answer:


<img src="responsive.jpg" alt="A responsive design example" width="400" height="300">

Why it works: Defining dimensions helps the browser allocate space, improving load performance and layout consistency.

Quick Reference Card

  • Core rule: Always use the alt attribute for accessibility.
  • Key formula: <img src="image.jpg" alt="description" width="300" height="200">
  • Three most critical facts:
  • alt text is essential for accessibility.
  • Use figure and figcaption for semantic grouping.
  • Define width and height for better performance.
  • One dangerous pitfall: Forgetting the alt attribute.
  • Mnemonic: "ALT for all images, Width and Height for layout."

If You're Stuck (Exam or Real Life)

  • What to check first: Verify the src attribute points to the correct image file.
  • How to reason from first principles: Think about how the browser renders images and the importance of accessibility.
  • When to use estimation: Estimate image dimensions if exact values are not available, but verify later.
  • Where to find the answer: Consult HTML documentation or use browser developer tools to inspect image elements.

Related Topics

  • Responsive Design: Learn how to make images adapt to different screen sizes.
  • Accessibility: Understand more about making web content accessible to all users.


ADVERTISEMENT