While searching for a way to check CSS support in browsers I came across two different approaches: CSS and JavaScript. I have used JS before for checking feature support in browsers, but not for CSS properties. From what I can tell newer browsers have added support for CSS @supports
, but what about the browsers that don't?
Example of CSS @supports
:
@supports (display: flex) {
div { display: flex; }
}
So, if older browsers don't support CSS @supports
, would it be practical to utilize both JS and CSS approaches? Regarding my example above, would it be possible to do almost an if/else statement with it such as:
@supports (display: flex) {
div { display: flex; }
} else {
div { display: none; }
}
I understand it probably wouldn't be the key word else
, but being able to perform something along those lines would be beneficial. So, to sum up and organize my questions:
- What is the best approach to checking CSS property support with
@supports
in older browsers not supporting this CSS syntax? - Would it make sense or be practical to utilize both CSS and JS for this?
- Is there some sort of
if/else
syntax for CSS@supports
?
if/else
syntax, this wouldn't be necessary as you'd use specificity to allow your@supports
declarations to override your regular declarations. – Offal@supports
until very recently. – Qualification