Skip to content

CSS variables

Inju Michorius edited this page May 17, 2021 · 2 revisions

Another cool thing you can do with css is creating variables and use them when styling elements. If you don't like the color for example, you can change all color of your website by changing one variable. You can create css variables in an element, but if you want to use the variable everywhere it's best to use the selector :root.

:root {
    --blue: #586598;
    --red: #DE4846;
    --gold: #e4bd34;
    --neptune: #419BB1;
}

After you've declared the variable, you can use it like the example below. When changing the variable name, you also have to change the name in the element.

body {
    background-color: var(--neptune);
}

You can put anything in a css variable, so it does not have to be a color. It could also be a font, size, value, position etc.

Weeks

Week 1 📕

Week 2 📙

CSS Techniques

CSS variables 🧠

Font-face 👁‍🗨

Fonts 🅰️

Keyframes 🥳

Custom everything!

Favicon 🌆

Cursor 🖱️

Scrollbar ⌨️

Selection 🧲

Clone this wiki locally