Close

Finally !!! CSS Variable has arrived.

CSS variables, more accurately known as CSS custom properties, are landing in Chrome 49. CSS is going to be like a CSS pre-processor itself such as SASS, LESS in the future.  CSS variables are now officially part of the CSS specification – details here.

CSSWG was experimenting about CSS variables since 2012 – details here . There is another news that Google has now joined Mozilla by supporting this great feature.

CSS Variables

 

Playing with CSS Variables.

  1. How it works.
  2. Override CSS variables.
  3. Override CSS variables in media query.
  4. CSS variable experiment with javascript.
  5. Browser support.

 

1- How it works.

I already mentioned that CSS variables are known as CSS custom properties.

Create a root class in CSS file.

Create a Variable ( You can declare anything in variable such as color, width .. )

Call your variables anywhere you want in that css file (you can replace ‘element’ with ‘body’ in this below code)

See the Pen CSS Variables by ShibinRagh (@shibinragh) on CodePen.

 

 

2) Override CSS Variables.

We can override all css variables – see the demo.

See the Pen CSS Variables override by ShibinRagh (@shibinragh) on CodePen.

 

 

3- Override CSS variables in media query.

We can include the variables with a different value in media query break points.

you can replace ‘element’ with ‘body’ in this below code

 

 

4- CSS Variables experimenting with Javascript.

Sharing CSS Variables with JavaScript.

See the Pen Pure CSS Variables Experiments with JavaScript by UXDots (@uxdots) on CodePen.

 

 

5- Browser support.

Firefox: Version 31+ (Enabled by default)
Chrome: Version 49+ (Enabled by default).
Safari/IOS Safari: Version 9.1/9.3 (Enabled by default).
IE Edge: In development.
CSS Variables

We can check browsers supporting details- can i use

Mozilla has posted an article about this – link

 

Conclusion.

CSS had already introduced calculation features calc it is an amazing feature, another one is flex-box, now they have introduced a variable feature.
Without doubt, we can say CSS Variables will be a supreme feature in future, at the moment it works only in the latest version of browsers. Web developers are really excited with that CSS as it is going to be awesome.!!!

 

 

Latest stories

  • How to build a scalable web application using Microservices Architecture

    Millions of people worldwide stream more than two billion hours worth of video from Netflix each month. Another example is Facebook, which roughly had 2.85 billion active users in the first quarter of 2021. Talking about the e-commerce giant, Amazon receives more than 66 thousand orders per hour, and 18.5 orders per second. Whoooo! So, […]

  • Flutter vs React Native: What to choose in 2021

    If Flutter vs React Native is your burgeoning question for this year 2021, guess what you are not alone. We no longer need statistics to know about the ever-growing popularity of mobile apps across the world. According to the latest report, global consumers are now spending an average of 4.2 hours per day using apps […]

  • React Native App development: Top Reasons to Choose It in 2021

    The promising cross-platform app development framework aka React Native has garnered huge popularity in recent times. The technology enables simultaneous mobile app development for multiple platforms using a single and a fraction of resources required for native development. The react native framework has emerged to be a popular choice among businesses to fulfill their cross-platform […]

Leave a Reply

Your email address will not be published. Required fields are marked *