Root scope and Syntax - CSS variables

Akash Gutha
InstructorAkash Gutha
Share this video with your friends

Social Share Links

Send Tweet
Published 5 years ago
Updated 3 years ago

In this lesson, we will take a look at the syntax of CSS variables. We’ll explore what the root scope is and how is it used, it's syntax. We’ll also look at the basic syntax required to use css variables.

Instructor: [00:00] I've prepared a document with three paragraphs that contain simple lorem ipsum text. Then, we'll add styles to this document. Let's add in a style to the paragraph text and give it a color of red.

[00:13] As you can see, the change of color has been reflected in our web browser. Now, let's start with our first concept, known as the root scope. Now, you can think about the root scope as global context or global variable.

[00:26] Whatever you put inside these curly braces will be accessible throughout your web page. Now, let's add in our first variable which we'll be calling our primary color and give it a value of red.

[00:38] To use the CSS variable, we write var, and then parentheses, and then inside the parentheses, we write the exact variable declaration name. If you refresh the web page, you can see that the red color is reflected here.

[00:52] Now, let's try changing the value of the primary color to pink. As you can see, the changes are reflected in the web browser. Now, let's try changing it to orange. The changes are still reflected in the web browser.

[01:06] Now, let's try changing the variable's name to have a single dash at the starting. As you can see, the value falls back to black and the primary color is now not affecting the text anymore. That is because the CSS variable standard required you to start every variable with two dashes, or else it's going to fall back to the default value in this case, which is black.

egghead
egghead
~ just now

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today