Challenge - 5 Problems
Image Sizing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ rendering
intermediate2:00remaining
What size will the image appear in the browser?
Given this HTML code, what will be the displayed width and height of the image in the browser?
<img src="flower.jpg" width="200" height="100" alt="Flower">HTML
<img src="flower.jpg" width="200" height="100" alt="Flower">
Attempts:
2 left
💡 Hint
Width and height attributes set the image size in pixels unless CSS overrides them.
✗ Incorrect
The width and height attributes in the <img> tag set the displayed size in pixels. Here, width=200 and height=100 means the image will appear 200 pixels wide and 100 pixels tall.
🧠 Conceptual
intermediate2:00remaining
What happens if only width is set on an image?
Consider this HTML:
What will happen to the image's height when displayed?
<img src="tree.jpg" width="300" alt="Tree">What will happen to the image's height when displayed?
HTML
<img src="tree.jpg" width="300" alt="Tree">
Attempts:
2 left
💡 Hint
Browsers keep the image's aspect ratio if only one dimension is set.
✗ Incorrect
When only width is set, the browser calculates height automatically to keep the original aspect ratio. This prevents the image from looking stretched or squished.
❓ selector
advanced2:00remaining
Which CSS selector correctly resizes all images inside a element?
You want to make all images inside the <main> element have a width of 100% of their container. Which CSS selector and rule will do this?
Attempts:
2 left
💡 Hint
The selector should target img elements inside main elements.
✗ Incorrect
The selector 'main img' targets all img elements inside any main element. The rule sets their width to 100% of their container's width.
❓ accessibility
advanced2:00remaining
Why is the alt attribute important for images?
Which statement best explains why the alt attribute should always be included on <img> tags?
Attempts:
2 left
💡 Hint
Think about users who cannot see images.
✗ Incorrect
The alt attribute gives a text alternative describing the image. This helps screen readers for visually impaired users and shows text if the image cannot load.
❓ layout
expert3:00remaining
What is the visual result of this CSS on an image inside a flex container?
Given this HTML and CSS:
What will you see in the browser?
<div class="container"><img src="cat.jpg" alt="Cat"></div>.container { display: flex; width: 20rem; height: 10rem; } img { flex-shrink: 0; width: 15rem; height: 15rem; }What will you see in the browser?
HTML
<div class="container"><img src="cat.jpg" alt="Cat"></div> <style> .container { display: flex; width: 20rem; height: 10rem; } img { flex-shrink: 0; width: 15rem; height: 15rem; } </style>
Attempts:
2 left
💡 Hint
flex-shrink: 0 prevents shrinking smaller than set size.
✗ Incorrect
The container is 20rem wide and 10rem tall. The image is set to 15rem by 15rem and cannot shrink because flex-shrink is 0. So the image overflows vertically beyond the container's height.