0
0
Tailwindmarkup~20 mins

CSS variables with Tailwind - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
CSS Variables with Tailwind Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding CSS Variables in Tailwind
Which statement correctly describes how CSS variables can be used with Tailwind CSS?
ACSS variables can be defined in a <style> block or external CSS and then referenced inside Tailwind utility classes using var(--variable-name).
BTailwind automatically converts all CSS variables into fixed colors during build time, so you cannot use var() inside Tailwind classes.
CCSS variables cannot be used with Tailwind CSS because Tailwind only supports fixed values.
DCSS variables must be declared inside Tailwind config file to be used in utility classes.
Attempts:
2 left
💡 Hint
Think about how CSS variables work in normal CSS and how Tailwind utilities can reference them.
📝 Syntax
intermediate
2:00remaining
Using CSS Variables in Tailwind Utility Classes
Which Tailwind class correctly applies a background color using a CSS variable named --main-bg?
Abg--main-bg
Bbg-var(--main-bg)
Cbg-[var(--main-bg)]
Dbg(var(--main-bg))
Attempts:
2 left
💡 Hint
Tailwind uses square brackets to allow arbitrary values.
rendering
advanced
2:00remaining
Visual Result of CSS Variable with Tailwind
Given the CSS and HTML below, what color will the box's background be when rendered in the browser?
Tailwind
/* CSS */
:root {
  --box-color: #4ade80;
}

/* HTML */
<div class="w-40 h-40 bg-[var(--box-color)]"></div>
AA green box with a background color #4ade80
BA box with no background color (transparent)
CA box with a red background color
DThe box will not render due to invalid CSS
Attempts:
2 left
💡 Hint
Check the CSS variable value and how it is used in the Tailwind class.
selector
advanced
2:00remaining
Targeting Elements with CSS Variables and Tailwind
You want to create a button that changes its text color based on a CSS variable --btn-text. Which Tailwind class correctly applies this text color?
Atext--btn-text
Btext-[var(--btn-text)]
Ctext-var(--btn-text)
Dtext(var(--btn-text))
Attempts:
2 left
💡 Hint
Remember how Tailwind handles arbitrary values with square brackets.
accessibility
expert
3:00remaining
Ensuring Accessibility with CSS Variables and Tailwind
You use a CSS variable --primary-color for background and text colors in Tailwind. What is the best practice to ensure good accessibility (color contrast) for all users?
ASet the CSS variable colors only for light mode and ignore dark mode contrast.
BUse any colors you like in CSS variables because Tailwind automatically adjusts contrast.
CAvoid using CSS variables for colors and only use Tailwind's default color palette for accessibility.
DDefine the CSS variable with colors that meet WCAG contrast standards and test with tools; update variables if needed.
Attempts:
2 left
💡 Hint
Accessibility means good contrast and testing with real tools.