DEV Community

Cover image for Can I Use 'Variables' in CSS ? Yes !! Let's see how
Anuj Singh
Anuj Singh

Posted on

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

Top comments (0)