0
0
CSSmarkup~20 mins

Fallback values in CSS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
CSS Fallback Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate
1: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);
}
AThe text will be red.
BThe text will be black (default browser color).
CThe text will be transparent.
DThe text will be blue.
Attempts:
2 left
💡 Hint
Look at the second value inside the var() function.
🧠 Conceptual
intermediate
1:30remaining
Why use fallback values in CSS variables?
Which of the following is the main reason to use fallback values with CSS variables?
ATo make the CSS file smaller.
BTo provide a default style if the variable is not set or supported.
CTo speed up the browser rendering process.
DTo disable the variable feature in older browsers.
Attempts:
2 left
💡 Hint
Think about what happens if a variable is missing.
rendering
advanced
2: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;
}
AThe background color will be lightgray.
BThe background color will be the value of --bg-color.
CThe background color will be black.
DThe background color will be transparent.
Attempts:
2 left
💡 Hint
If the variable is missing, what does the fallback do?
selector
advanced
1: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?
Afont-size: var(--font-size, 16px);
Bfont-size: var(--font-size) || 16px;
Cfont-size: var(--font-size); fallback: 16px;
Dfont-size: var(--font-size 16px);
Attempts:
2 left
💡 Hint
Check the syntax of the var() function.
accessibility
expert
2: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?
ARely on browser defaults for color if the variable is missing.
BUse transparent fallback colors to avoid conflicts.
CChoose fallback colors with good contrast to ensure readability.
DUse the same color for fallback as the background color.
Attempts:
2 left
💡 Hint
Think about how color contrast affects people with vision difficulties.