Variables and Functions
Learn how to use CSS variables and functions to create more organized, efficient, and dynamic websites.
StartCSS Variables
Lesson 1 of 2
- 2CSS Variables are defined the same way as any other CSS declaration, making them syntactically convenient and easy to remember. Each variable declaration must begin with a double hyphen (–) follo…
- 3Now that we know how to define and initialize CSS variables, let’s learn how to use them. As we saw in the last exercise, when we define variables in place of hardcoded properties, the variable doe…
- 4Like other CSS properties, when we define a CSS variable, we are also giving that variable a set scope. In CSS, the scope is what determines where a variable will work based on where it is declar…
- 5Just as CSS variables are subjected to local and global scope, they also follow standard CSS inheritance. If a variable is not explicitly defined on a child element, the value of its parent variabl…
- 6Sometimes there are reasons why a given variable may be invalid when the webpage renders. For example, the variable could have been set improperly—a variable with a value of 20px could mistak…
- 7So far, we have seen how CSS variables make it easier to reuse and read CSS code. But variables are also extremely powerful when used with media queries to create responsive designs. By using vari…
What you'll create
Portfolio projects that showcase your new skills
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory