The part about being able to reuse it throughout the document was super appealing and then further down the page on MDN, I found this beauty.

Custom properties (sometimes referred to as CSS variables or cascading variables) are entities defined by CSS authors that contain specific values to be reused throughout a document. Our components pick a size from the scale, and we There are some CSS properties that simply can't be animated. Within this, I can place new CSS to override the original CSS. Updating CSS Variables with React. Themes Using CSS Variables and React Context. Before, it was possible for a wayward developer to accidentally delete one of the breakpoints.

Being able to access theme values without an import or an inline function is a breath of fresh air. This tutorial uses First, I'm going to assume that you have a file that holds all of your design tokens, something like this:In a React app, you might import them directly into the components that need them:Here's the same code, but set up using CSS variablesWe've created some variables, hung them on the root node, and now we can access them in our components:This is a nice little win, in my opinion. The reasons for that go well beyond the scope of this post.Another reason would be to make your UI components as universal as possible. Generally, it's obvious when you mistype the name of a CSS variable, and it's a quick fix.I think it's important to run compile-time checks on your site, but I think tools like CSS variables enjoy healthy browser support amongst the 4 leading browsers, but it's missing IE support:When using styled-components, you can put variables wherever you want, including within media queries:CSS variables can't be used anywhere within media queries.

You can do things with CSS variables that are They can hold any type of value, not just colors and pixels.You can attach them to any selector, not just the root You can specify a default value if the CSS variable isn't defined: By consolidating the breakpoint stuff in a single place, we now have a single source of truth. I also really like CSS. To place the