0
0
CSSmarkup~20 mins

Aspect ratio in CSS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Aspect Ratio Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
rendering
intermediate
2:00remaining
What 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;
}
AA rectangle wider than it is tall, with width 320px and height 180px
BA square with width and height both 320px
CA tall rectangle with width 180px and height 320px
DA circle with diameter 320px
Attempts:
2 left
💡 Hint
Aspect ratio controls the width to height ratio of the box.
📝 Syntax
intermediate
1:30remaining
Which CSS rule correctly sets a 4:3 aspect ratio?
Choose the CSS rule that correctly sets an element's aspect ratio to 4:3.
Aaspect-ratio: 4:3;
Baspect-ratio: 3 / 4;
Caspect-ratio: 4 / 3;
Daspect-ratio: "4/3";
Attempts:
2 left
💡 Hint
The aspect-ratio property uses a slash (/) between numbers without quotes.
layout
advanced
2:00remaining
How 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;
}
AHeight will be 400px, double the width.
BHeight will be auto ignoring aspect-ratio.
CHeight will be 100px, half the width.
DHeight will be 200px, making the child a square.
Attempts:
2 left
💡 Hint
Aspect ratio sets height based on width when height is not fixed.
accessibility
advanced
1:30remaining
Why is using aspect-ratio helpful for accessibility?
Which reason best explains how aspect-ratio improves accessibility in web design?
AIt changes font sizes for better readability.
BIt prevents layout shifts by reserving space, helping screen readers and keyboard users.
CIt automatically adds ARIA labels to images.
DIt disables animations that distract users.
Attempts:
2 left
💡 Hint
Think about how stable layouts help all users.
🧠 Conceptual
expert
2:30remaining
What 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;
}
AThe box will be 300px wide and 200px tall, ignoring aspect-ratio.
BThe box height adjusts to 168.75px to keep 16:9 ratio with width 300px.
CThe box width adjusts to 355.56px to keep 16:9 ratio with height 200px.
DThe box size is invalid and will not render.
Attempts:
2 left
💡 Hint
When both width and height are set, aspect-ratio is ignored.