Challenge - 5 Problems
CSS Fallback Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate1:30remaining
What color will the text be?
Given the CSS below, what color will the text inside the <p> tag appear as if the variable
--main-color is NOT defined?CSS
p {
color: var(--main-color, blue);
}Attempts:
2 left
💡 Hint
Look at the second value inside the var() function.
✗ Incorrect
The CSS uses a fallback value 'blue' for the custom property '--main-color'. If '--main-color' is not defined, the fallback 'blue' is used.
🧠 Conceptual
intermediate1:30remaining
Why use fallback values in CSS variables?
Which of the following is the main reason to use fallback values with CSS variables?
Attempts:
2 left
💡 Hint
Think about what happens if a variable is missing.
✗ Incorrect
Fallback values ensure the style still works even if the variable is missing or unsupported, improving robustness.
❓ rendering
advanced2:00remaining
What background color will the box have?
Consider this CSS snippet. What background color will the <div> have if the browser supports CSS variables but the variable
--bg-color is NOT defined anywhere?CSS
div {
background-color: var(--bg-color, lightgray);
width: 100px;
height: 100px;
}Attempts:
2 left
💡 Hint
If the variable is missing, what does the fallback do?
✗ Incorrect
The fallback value 'lightgray' is used because the variable '--bg-color' is not defined.
❓ selector
advanced1:30remaining
Which CSS rule applies fallback correctly?
Which of the following CSS rules correctly uses a fallback value for the font size variable
--font-size?Attempts:
2 left
💡 Hint
Check the syntax of the var() function.
✗ Incorrect
The correct syntax for fallback is var(--variable, fallback). Options A, C, and D are invalid CSS syntax.
❓ accessibility
expert2:30remaining
How do fallback colors affect accessibility?
If a CSS variable for text color is missing and the fallback color has poor contrast with the background, what is the best practice to maintain accessibility?
Attempts:
2 left
💡 Hint
Think about how color contrast affects people with vision difficulties.
✗ Incorrect
Fallback colors should always maintain good contrast to keep text readable for all users, including those with visual impairments.