0
0
HTMLmarkup~20 mins

Image sizing basics in HTML - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Image Sizing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
rendering
intermediate
2: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">
AThe image will stretch to fill the entire browser window.
BThe image will keep its original size ignoring width and height attributes.
CThe image will be 100 pixels wide and 200 pixels tall.
DThe image will be 200 pixels wide and 100 pixels tall.
Attempts:
2 left
💡 Hint
Width and height attributes set the image size in pixels unless CSS overrides them.
🧠 Conceptual
intermediate
2:00remaining
What happens if only width is set on an image?
Consider this HTML:

<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">
AThe height will stretch to fill the browser window height.
BThe height will be zero, so the image will not show.
CThe height will adjust automatically to keep the image's original proportions.
DThe height will be set to 300 pixels, making the image square.
Attempts:
2 left
💡 Hint
Browsers keep the image's aspect ratio if only one dimension is set.
selector
advanced
2: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?
Amain img { width: 100%; }
Bimg main { width: 100%; }
C.main > img { width: 100%; }
Dimg > main { width: 100%; }
Attempts:
2 left
💡 Hint
The selector should target img elements inside main elements.
accessibility
advanced
2:00remaining
Why is the alt attribute important for images?
Which statement best explains why the alt attribute should always be included on <img> tags?
AIt changes the image size automatically to fit the screen.
BIt provides a text description for screen readers and shows if the image fails to load.
CIt adds a border around the image for better visibility.
DIt hides the image from all users to improve page speed.
Attempts:
2 left
💡 Hint
Think about users who cannot see images.
layout
expert
3:00remaining
What is the visual result of this CSS on an image inside a flex container?
Given this HTML and CSS:

<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>
AThe image will be 15rem by 15rem, overflowing vertically outside the 10rem container height.
BThe image will shrink to fit inside the 20rem by 10rem container exactly.
CThe image will stretch to fill the container width and height.
DThe image will disappear because flex-shrink is zero.
Attempts:
2 left
💡 Hint
flex-shrink: 0 prevents shrinking smaller than set size.