0
0
CSSmarkup~5 mins

Using variables in CSS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a CSS variable?
A CSS variable is a custom property that stores a value you can reuse throughout your CSS. It starts with two dashes, like --main-color.
Click to reveal answer
beginner
How do you declare a CSS variable?
You declare a CSS variable inside a selector using the syntax: --variable-name: value;. For example, :root { --main-color: #3498db; } sets a variable named --main-color.
Click to reveal answer
beginner
How do you use a CSS variable in your styles?
Use the var() function with the variable name. For example, color: var(--main-color); applies the value stored in --main-color.
Click to reveal answer
beginner
Why use CSS variables instead of repeating values?
CSS variables make it easy to change a value in one place and have it update everywhere. This saves time and keeps your styles consistent.
Click to reveal answer
beginner
Where is the best place to declare global CSS variables?
Declare global CSS variables inside the :root selector. This makes them available everywhere in your CSS.
Click to reveal answer
How do you declare a CSS variable named --bg-color with the value #fff?
Abackground-color: --bg-color #fff;
B:root { --bg-color: #fff; }
Cvar(--bg-color) = #fff;
Dbody { bg-color = #fff; }
How do you use a CSS variable named --text-color to set text color?
Acolor: var(--text-color);
Bcolor: --text-color;
Cvar(text-color);
Dtext-color: var(--text-color);
What is the advantage of using CSS variables?
AThey are required for all CSS.
BThey make CSS run faster.
CThey replace HTML tags.
DThey let you reuse values and update them easily.
Where should you declare CSS variables to make them available everywhere?
A:root selector
BInside each HTML tag
COnly inside <style> tags
DInside JavaScript files
Which of these is a correct CSS variable name?
Amain-font
B$main-font
C--main-font
Dvar-main-font
Explain how to create and use a CSS variable to set a background color.
Think about how you store a color once and reuse it.
You got /4 concepts.
    Describe the benefits of using CSS variables in a website's style.
    Imagine changing one color everywhere by changing just one place.
    You got /4 concepts.