What does the src attribute in an <img> tag specify?
The src attribute tells the browser the location (URL or path) of the image file to display.
Click to reveal answer
beginner
Why is the alt attribute important for images?
The alt attribute provides alternative text describing the image. It helps screen readers for visually impaired users and shows text if the image fails to load.
Click to reveal answer
beginner
Write a simple <img> tag with a source of "cat.jpg" and alt text "A cute cat".
<img src="cat.jpg" alt="A cute cat">
Click to reveal answer
beginner
What happens if an image's src is incorrect or the image file is missing?
The browser shows the alt text instead of the image, helping users understand what was supposed to be there.
Click to reveal answer
intermediate
Can the alt attribute be empty? When would you do this?
Yes, alt="" means the image is decorative and screen readers will skip it. Use this for images that don’t add important info.
Click to reveal answer
What does the src attribute in an <img> tag do?
AProvides alternative text
BSpecifies the image file location
CSets the image size
DDefines the image border
✗ Incorrect
The src attribute tells the browser where to find the image file to display.
Why should you always include an alt attribute in images?
ATo add a border around the image
BTo improve page loading speed
CTo describe the image for screen readers and when images fail to load
DTo change the image color
✗ Incorrect
The alt attribute helps users who can’t see the image understand its content.
What will a browser show if the image file in src is missing?
ANothing at all
BA broken image icon only
CThe page will crash
DThe <code>alt</code> text
✗ Incorrect
If the image can’t load, the browser displays the alt text to explain what was missing.
How do you mark an image as decorative so screen readers ignore it?
ASet <code>alt=""</code> (empty string)
BUse <code>src="decorative.jpg"</code>
CUse <code>alt="decorative"</code>
DOmit the <code>alt</code> attribute
✗ Incorrect
An empty alt attribute tells screen readers to skip the image because it’s only decorative.
Which of these is a correct <img> tag?
A<img src="sunset.jpg" alt="Sunset">
B<img alt="Sunset">
C<img src="sunset.jpg">
D<img source="sunset.jpg" alt="Sunset">
✗ Incorrect
The correct attributes are src for the image file and alt for alternative text.
Explain why the alt attribute is important for web images.
Think about users who cannot see images.
You got /3 concepts.
Describe how to write an <img> tag with both source and alt text.
Remember both attributes are needed for good practice.
You got /3 concepts.
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
Step 1: Understand the purpose of the alt attribute
The alt attribute provides alternative text describing the image content.
Step 2: Recognize its use for accessibility and fallback
This text helps screen readers and shows if the image fails to load.
Final Answer:
Provides a text description of the image for screen readers and when the image can't load -> Option A
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
Step 1: Identify correct tag and attributes
The correct tag is <img> with attributes src and alt.
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".
Final Answer:
<img src="photo.jpg" alt="A sunset"> -> Option A
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
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.
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.
Final Answer:
The text "Company Logo" will appear instead of the image -> Option D
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
Step 1: Check the alt attribute syntax
The alt attribute is present but has no value assigned, which is invalid.
Step 2: Confirm correct attribute names and tag usage
The src attribute is correct, and <img> is self-closing, so no closing tag needed.
Final Answer:
The alt attribute is missing a value -> Option C
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
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.
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.
Final Answer:
<img src="cat-ball.jpg" alt="Cat playing with a ball"> -> Option B
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 unknownstrongwhile earning +1 Grip toward your certificate.