0
0
HTMLmarkup~5 mins

Image source and alt attribute in HTML - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
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
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
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
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
Which of these is a correct <img> tag?
A&lt;img src="sunset.jpg" alt="Sunset"&gt;
B&lt;img alt="Sunset"&gt;
C&lt;img src="sunset.jpg"&gt;
D&lt;img source="sunset.jpg" alt="Sunset"&gt;
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.