Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Css property support detection

Tags:

javascript

Is there a generic way in javascript to check if the css property is supported by current browser or not?

I am currently using "document.compatMode" to check if it is quirks or not. But there must be a way to check specific to a property.

like image 728
emphaticsunshine Avatar asked Jan 19 '26 22:01

emphaticsunshine


2 Answers

You can do this, ex:

typeof document.body.style.borderRadius

In supported browsers, it should return 'string'. In non supported, it will be 'undefined'

like image 150
Ricardo Bin Avatar answered Jan 22 '26 11:01

Ricardo Bin


There is a new DOM API CSS.supports for that purpose. FF, Opera (as supportsCSS) and Chrome Canary already implement this method.

For cross-browser compatibility you can use my CSS.supports polyfill

Example:

CSS.supports("display", "table");//IE<8 return false

But, you still need to specify browser prefix for prefixing css properties. For example:

CSS.supports("-webkit-filter", "blur(10px)");

I suggest to using Modernizr for feature-detection.

like image 20
termi Avatar answered Jan 22 '26 10:01

termi