0
0
CSSmarkup~20 mins

Using variables in CSS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
CSS Variable Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate
2:00remaining
What is the value of color in this CSS snippet?
Given the CSS below, what color will the h1 text be rendered in the browser?
CSS
:root {
  --main-color: #3498db;
}
h1 {
  color: var(--main-color);
}
AThe text color will be black (default).
BThe text color will be blue (#3498db).
CThe text color will be red.
DThe text color will be transparent.
Attempts:
2 left
💡 Hint
Look at how the variable --main-color is defined and used.
🧠 Conceptual
intermediate
2:00remaining
Which CSS variable scope is correct for this behavior?
You want a CSS variable --btn-bg to have different values inside .card and outside it. Which scope should you use to achieve this?
ADefine <code>--btn-bg</code> inside <code>.card</code> and also in <code>:root</code> with different values.
BDefine <code>--btn-bg</code> only in <code>:root</code>.
CDefine <code>--btn-bg</code> only inside <code>.card</code>.
DDefine <code>--btn-bg</code> inside <code>body</code> only.
Attempts:
2 left
💡 Hint
Variables cascade and inherit from their scope.
selector
advanced
2:00remaining
What color will the p text have?
Consider the CSS below. What color will the p inside .container be?
CSS
:root {
  --text-color: black;
}
.container {
  --text-color: red;
}
.container p {
  color: var(--text-color, blue);
}
ABlue
BBlack
CTransparent
DRed
Attempts:
2 left
💡 Hint
Variables cascade and the closest scope applies.
layout
advanced
2:00remaining
How does using CSS variables improve layout flexibility?
Which statement best explains how CSS variables help when adjusting layout spacing?
AThey allow changing spacing values in one place to update all related elements.
BThey automatically resize elements based on screen size without media queries.
CThey replace the need for Flexbox or Grid layouts.
DThey prevent any layout changes once set.
Attempts:
2 left
💡 Hint
Think about how variables can be reused.
accessibility
expert
3:00remaining
How can CSS variables improve accessibility for users with visual impairments?
Which approach using CSS variables best supports users who need high contrast themes?
AUse CSS variables only for font sizes, not colors.
BUse fixed colors in CSS without variables to ensure consistency.
CDefine color variables and switch their values with a toggle to provide high contrast themes.
DAvoid using color variables to prevent confusion.
Attempts:
2 left
💡 Hint
Think about how variables can be changed dynamically.