0
0
Tailwindmarkup~5 mins

CSS variables with Tailwind - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a CSS variable and why use it?
A CSS variable is a custom property that stores a value you can reuse throughout your styles. It helps keep your design consistent and makes updates easier by changing the value in one place.
Click to reveal answer
beginner
How do you define a CSS variable in Tailwind's :root?
You define CSS variables inside the :root selector in your CSS file or inside a @layer base block in Tailwind. For example:<br>
:root { --main-color: #4ade80; }
Click to reveal answer
intermediate
How can you use a CSS variable inside Tailwind utility classes?
You can use the var(--variable-name) syntax inside Tailwind's theme.extend or directly in your CSS. For example, setting a background color: bg-[color:var(--main-color)] applies the CSS variable as a background color.
Click to reveal answer
intermediate
Why combine CSS variables with Tailwind instead of only using Tailwind colors?
CSS variables let you change colors dynamically (like dark mode or themes) without rebuilding Tailwind classes. They add flexibility and make your design easier to maintain and customize.
Click to reveal answer
intermediate
How do you update a CSS variable value for a dark mode theme in Tailwind?
You can override the CSS variable inside a dark mode selector. For example:<br>
@media (prefers-color-scheme: dark) { :root { --main-color: #22c55e; } }
This changes the variable when dark mode is active.
Click to reveal answer
Where do you usually define CSS variables for use with Tailwind?
AInside the :root selector or @layer base in CSS
BDirectly inside Tailwind config colors array
COnly inside HTML style attributes
DInside JavaScript files
How do you reference a CSS variable in Tailwind utility classes?
AUsing $variable-name directly
BYou cannot use CSS variables in Tailwind classes
CUsing --variable-name without var()
DUsing var(--variable-name) inside square brackets, e.g., bg-[color:var(--main-color)]
What is a main benefit of using CSS variables with Tailwind?
AThey replace Tailwind colors completely
BThey allow dynamic theming without rebuilding Tailwind classes
CThey make Tailwind slower
DThey only work in old browsers
How can you change a CSS variable for dark mode in Tailwind?
AYou cannot change CSS variables for dark mode
BChange the Tailwind config colors only
COverride the variable inside a dark mode media query or class
DUse inline styles on every element
Which syntax is correct to define a CSS variable for a green color?
A:root { --main-green: #22c55e; }
Bvar(--main-green): #22c55e;
C--main-green: #22c55e;
Dmain-green = #22c55e;
Explain how to set up and use a CSS variable for colors in a Tailwind project.
Think about where CSS variables live and how Tailwind allows custom values.
You got /4 concepts.
    Describe how CSS variables help implement dark mode in Tailwind.
    Focus on how variable values change depending on theme.
    You got /4 concepts.