Challenge - 5 Problems
Aspect Ratio Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ rendering
intermediateWhat is the visible shape of this box?
Given the CSS below, what shape will the box appear as in the browser?
CSS
div {
aspect-ratio: 16 / 9;
width: 320px;
background-color: lightblue;
}Attempts:
2 left
๐ก Hint
Aspect ratio controls the width to height ratio of the box.
โ Incorrect
The aspect-ratio 16 / 9 means width is 16 units and height is 9 units. With width fixed at 320px, height is calculated as 320 * 9 / 16 = 180px, making a wide rectangle.
๐ Syntax
intermediateWhich CSS rule correctly sets a 4:3 aspect ratio?
Choose the CSS rule that correctly sets an element's aspect ratio to 4:3.
Attempts:
2 left
๐ก Hint
The aspect-ratio property uses a slash (/) between numbers without quotes.
โ Incorrect
The correct syntax uses a slash between numbers without quotes. Option C is correct. Option C reverses ratio. Options C and D use invalid syntax.
โ layout
advancedHow does aspect-ratio affect a flex item with fixed width?
Consider a flex container with a child having fixed width and aspect-ratio set. What will be the child's height?
CSS
div.container { display: flex; } div.child { width: 200px; aspect-ratio: 1 / 1; background-color: coral; }
Attempts:
2 left
๐ก Hint
Aspect ratio sets height based on width when height is not fixed.
โ Incorrect
With width fixed at 200px and aspect-ratio 1 / 1, height is calculated as 200px to keep a square shape.
โ accessibility
advancedWhy is using aspect-ratio helpful for accessibility?
Which reason best explains how aspect-ratio improves accessibility in web design?
Attempts:
2 left
๐ก Hint
Think about how stable layouts help all users.
โ Incorrect
Using aspect-ratio reserves space before content loads, preventing layout shifts. This stability helps screen readers and keyboard navigation by keeping focus and content predictable.
๐ง Conceptual
expertWhat happens if both width and height are set along with aspect-ratio?
Given this CSS, what will be the final size of the box?
CSS
div {
width: 300px;
height: 200px;
aspect-ratio: 16 / 9;
background-color: lightgreen;
}Attempts:
2 left
๐ก Hint
When both width and height are set, aspect-ratio is ignored.
โ Incorrect
If both width and height are explicitly set, aspect-ratio is ignored and the box uses those exact dimensions.
