Categories
JavaScript Answers

How to detect CSS variable support with JavaScript?

Spread the love

Sometimes, we want to detect CSS variable support with JavaScript.

In this article, we’ll look at how to detect CSS variable support with JavaScript.

How to detect CSS variable support with JavaScript?

To detect CSS variable support with JavaScript, we can use the CSS.supports method.

For instance, we write:

console.log(CSS.supports('color', 'var(--fake-var)'))

to check if we can set the color CSS property to var(--fake-var).

If this returns true, then CSS variables is supported.

Conclusion

To detect CSS variable support with JavaScript, we can use the CSS.supports method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

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