Can I Use 'Variables' in CSS ? Yes !! Let's see how

singhanuj620

Anuj Singh

Posted on July 3, 2020

Can I Use 'Variables' in CSS ? Yes !! Let's see how

I am into the web development field for a quite long time now, but I am today year old when discovered that we can use variables in our CSS3.

So let's get started.

Assume that you are applying font-family property to 4 or 5 elements and that's where variable comes into action.

The variable with its property is defined and declared in :root with -- prefixed with the variable name.

:root {
    --varfont: 'Roboto', sans-serif;
}
Enter fullscreen mode Exit fullscreen mode

And use it like this :

h1
{
  font-family: var(--varfont);
}
Enter fullscreen mode Exit fullscreen mode

Hope it helped you !!!

Follow me for more such content :
Instagram : https://instagram.com/anujcodeop
Portfolio : https://anujportfolio.herokuapp.com

💖 💪 🙅 🚩
singhanuj620
Anuj Singh

Posted on July 3, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related