0
0
CSSmarkup~20 mins

Responsive images in CSS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Responsive Images Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding the srcset attribute
Which of the following img tags correctly uses the srcset attribute to provide different image sizes for responsive loading?
CSS
<img src="small.jpg" srcset="medium.jpg 600w, large.jpg 1200w" alt="Sample image">
A<img src="small.jpg" srcset="medium.jpg 600, large.jpg 1200" alt="Sample image">
B<img src="small.jpg" srcset="medium.jpg, large.jpg" alt="Sample image">
C<img src="small.jpg" srcset="medium.jpg 600w, large.jpg 1200w" alt="Sample image">
D<img src="small.jpg" srcset="600w:medium.jpg, 1200w:large.jpg" alt="Sample image">
Attempts:
2 left
💡 Hint
Look for the correct syntax where each image URL is followed by its width descriptor with 'w'.
📝 Syntax
intermediate
2:00remaining
Correct usage of sizes attribute
What is the correct way to use the sizes attribute to specify that the image should be 100vw (full viewport width) on screens smaller than 600px and 50vw on larger screens?
CSS
<img src="image.jpg" srcset="image-small.jpg 600w, image-large.jpg 1200w" sizes="(max-width: 600px) 100vw, 50vw" alt="Responsive image">
A<img src="image.jpg" srcset="image-small.jpg 600w, image-large.jpg 1200w" sizes="(max-width: 600px) 100vw, 50vw" alt="Responsive image">
B<img src="image.jpg" srcset="image-small.jpg 600w, image-large.jpg 1200w" sizes="100vw (max-width: 600px), 50vw" alt="Responsive image">
C<img src="image.jpg" srcset="image-small.jpg 600w, image-large.jpg 1200w" sizes="(max-width: 600px): 100vw, 50vw" alt="Responsive image">
D<img src="image.jpg" srcset="image-small.jpg 600w, image-large.jpg 1200w" sizes="(max-width: 600px) => 100vw, 50vw" alt="Responsive image">
Attempts:
2 left
💡 Hint
The sizes attribute uses media conditions followed by the size value, separated by commas.
rendering
advanced
2:00remaining
Visual result of picture element with media queries
Given the following HTML, what image will display on a screen width of 500px?
CSS
<picture>
  <source media="(min-width: 800px)" srcset="large.jpg">
  <source media="(min-width: 400px)" srcset="medium.jpg">
  <img src="small.jpg" alt="Responsive image">
</picture>
AThe image 'medium.jpg' will display.
BThe image 'large.jpg' will display.
CThe image 'small.jpg' will display.
DNo image will display because of conflicting media queries.
Attempts:
2 left
💡 Hint
Check which media queries match the screen width of 500px.
selector
advanced
2:00remaining
CSS selector for responsive images inside a container
Which CSS selector correctly targets all img elements inside a section with class gallery to make them responsive with max-width 100% and height auto?
A.gallery > img { max-width: 100%; height: auto; }
Bimg.gallery section { max-width: 100%; height: auto; }
Csection .gallery img { max-width: 100%; height: auto; }
Dsection.gallery img { max-width: 100%; height: auto; }
Attempts:
2 left
💡 Hint
The selector should target img inside section with class gallery.
accessibility
expert
3:00remaining
Accessibility best practice for responsive images
Which option best describes the correct way to provide accessible alternative text for responsive images using the picture element?
CSS
<picture>
  <source media="(min-width: 800px)" srcset="large.jpg">
  <source media="(min-width: 400px)" srcset="medium.jpg">
  <img src="small.jpg" alt="A scenic mountain landscape at sunrise">
</picture>
AOmit alt text on the <code>img</code> tag and add aria-label to the <code>picture</code> element.
BProvide meaningful alt text only on the <code>img</code> tag; sources do not need alt attributes.
CAdd alt attributes to all <code>source</code> tags with the same text as the <code>img</code> alt.
DUse empty alt text on the <code>img</code> tag and provide a caption outside the <code>picture</code> element.
Attempts:
2 left
💡 Hint
Remember which element is actually rendered and read by screen readers.