Bird
Raised Fist0
HTMLmarkup~20 mins

Image source and alt attribute in HTML - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Image Alt Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding the purpose of the alt attribute
Why is the alt attribute important for an <img> tag in HTML?
AIt provides alternative text for screen readers and shows if the image fails to load.
BIt sets the image size automatically based on the text length.
CIt links the image to another webpage when clicked.
DIt changes the image format from PNG to JPEG.
Attempts:
2 left
💡 Hint
Think about accessibility and what happens if the image cannot be displayed.
📝 Syntax
intermediate
2:00remaining
Correct syntax for image source and alt
Which of the following <img> tags is correctly written with both src and alt attributes?
A<img src="photo.jpg" alt="A beautiful sunrise">
B<img alt="A beautiful sunrise" source="photo.jpg">
C<img src=photo.jpg alt=>
D<img src="photo.jpg" alt>
Attempts:
2 left
💡 Hint
Check attribute names and if values are properly quoted.
❓ rendering
advanced
2:00remaining
What is displayed if image source is broken?
Given this HTML code:
<img src="missing.jpg" alt="Logo image">

What will the browser show if missing.jpg does not exist?
AThe browser will crash with an error.
BNothing will appear; the image area will be empty.
CThe text 'Logo image' will be shown where the image should be.
DA broken image icon with no text will appear.
Attempts:
2 left
💡 Hint
Think about fallback content for images that fail to load.
❓ selector
advanced
2:00remaining
Selecting images with missing alt attributes using CSS
Which CSS selector targets all <img> elements that do NOT have an alt attribute?
Aimg:empty
Bimg[alt='']
Cimg[alt]
Dimg:not([alt])
Attempts:
2 left
💡 Hint
Look for a selector that matches elements missing a specific attribute.
❓ accessibility
expert
2:00remaining
Best practice for decorative images and alt attribute
For purely decorative images that add no information, what is the best way to use the alt attribute to keep the page accessible?
AWrite <code>alt="decorative image"</code> to describe it.
BSet <code>alt=""</code> (empty string) to hide it from screen readers.
COmit the <code>alt</code> attribute entirely.
DUse <code>alt="image"</code> as a generic description.
Attempts:
2 left
💡 Hint
Think about how screen readers treat empty alt attributes.

Practice

(1/5)
1. What does the alt attribute in an <img> tag do?
easy
A. Provides a text description of the image for screen readers and when the image can't load
B. Specifies the URL of the image to display
C. Sets the size of the image on the page
D. Adds a border around the image

Solution

  1. Step 1: Understand the purpose of the alt attribute

    The alt attribute provides alternative text describing the image content.
  2. Step 2: Recognize its use for accessibility and fallback

    This text helps screen readers and shows if the image fails to load.
  3. Final Answer:

    Provides a text description of the image for screen readers and when the image can't load -> Option A
  4. Quick Check:

    alt describes image content [OK]
Hint: Alt text describes images for accessibility and fallback [OK]
Common Mistakes:
  • Confusing alt with src attribute
  • Thinking alt controls image size
  • Using alt to add styling
2. Which of the following is the correct syntax to add an image with source "photo.jpg" and alt text "A sunset"?
easy
A.
B.
C.
D.

Solution

  1. Step 1: Identify correct tag and attributes

    The correct tag is <img> with attributes src and alt.
  2. Step 2: Check attribute names and order

    <img src="photo.jpg" alt="A sunset"> uses correct attribute names and syntax: src="photo.jpg" and alt="A sunset".
  3. Final Answer:

    <img src="photo.jpg" alt="A sunset"> -> Option A
  4. Quick Check:

    Correct tag and attributes = <img src="photo.jpg" alt="A sunset"> [OK]
Hint: Use <img> with src and alt attributes exactly named [OK]
Common Mistakes:
  • Using <image> instead of <img>
  • Using 'source' instead of 'src'
  • Using 'description' instead of 'alt'
3. What will the browser display if this code is used and the image file "logo.png" is missing?
<img src="logo.png" alt="Company Logo">
medium
A. Nothing will show, just empty space
B. The browser will crash
C. An error message will pop up
D. The text "Company Logo" will appear instead of the image

Solution

  1. Step 1: Understand what happens when image source is missing

    If the image file can't be found, the browser shows the alt text as a fallback.
  2. Step 2: Identify the alt text in the code

    The alt text is "Company Logo", so this text will display in place of the missing image.
  3. Final Answer:

    The text "Company Logo" will appear instead of the image -> Option D
  4. Quick Check:

    Missing image shows alt text [OK]
Hint: Missing images show alt text in browser [OK]
Common Mistakes:
  • Expecting no output or blank space
  • Thinking browser shows error popups
  • Assuming browser crashes
4. Find the error in this image tag:
<img src="picture.jpg" alt>
medium
A. The img tag should be closed with
B. The src attribute is misspelled
C. The alt attribute is missing a value
D. The alt attribute should be written as alt-text

Solution

  1. Step 1: Check the alt attribute syntax

    The alt attribute is present but has no value assigned, which is invalid.
  2. Step 2: Confirm correct attribute names and tag usage

    The src attribute is correct, and <img> is self-closing, so no closing tag needed.
  3. Final Answer:

    The alt attribute is missing a value -> Option C
  4. Quick Check:

    Alt attribute must have a value [OK]
Hint: Alt attribute always needs a descriptive value [OK]
Common Mistakes:
  • Leaving alt attribute empty
  • Adding closing tag
  • Changing alt attribute name incorrectly
5. You want to add an image that shows a cat playing with a ball. Which is the best way to write the <img> tag for accessibility and SEO?
hard
A.
B.
C.
D.

Solution

  1. Step 1: Understand the purpose of alt text for accessibility and SEO

    Alt text should clearly describe the image content to help screen readers and improve search engine understanding.
  2. Step 2: Evaluate the options for descriptive quality

    <img src="cat-ball.jpg" alt="Cat playing with a ball"> describes the image specifically as "Cat playing with a ball", which is clear and meaningful.
  3. Final Answer:

    <img src="cat-ball.jpg" alt="Cat playing with a ball"> -> Option B
  4. Quick Check:

    Descriptive alt text improves accessibility and SEO [OK]
Hint: Use clear, specific alt text describing the image content [OK]
Common Mistakes:
  • Using vague alt text like 'image' or 'cute'
  • Omitting alt attribute entirely
  • Using unrelated or too short alt text
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard