Transcript
When using new or experimental CSS, it can be useful to know if the browser supports the features we’re writing code for.
Feature detection is often done in JavaScript with tools like Modernizr but in some browsers, we can now detect capabilities from CSS.
The @supports
rule allows us to conditionally apply styles for features that are or are not supported.
In this episode we’ll learn all about
- Browser support for various CSS features
- How the
@supports
at-rule works - and how to provide alternative styles for unsupported features
Browser Support
If you’ve been writing CSS for any length of time, you’ve probably discovered that not all browsers render things the same way and don’t all support the same features.
A fantastic resource that I use almost daily for checking browser support is the website caniuse.com.
This site allows you to search a database of support tables to find out which versions of which browsers support which features.
In the previous episode we learned about the :required
pseudo class, which is supported in IE10, Firefox, Chrome, Safari, Opera and Blackberry but not Opera Mini or iOS Safari or Android Browser.
We also learned about @keyframes
in episode 11 which are supported in all current browsers apart from Opera Mini but is only available in IE from version 10 and is prefixed in Chrome, Safari, Opera, Android and Blackberry.
As you can see, the feature support landscape is vast and complex. This resource is amazing and an integral part of knowing what will work under what browsing conditions. It allows us to decide what features we may need to provide fallbacks for in case the required feature is key to the design or functionality of the site.
The @supports rule
@supports
is an at-rule, a bit like the @media
queries which we looked at in Episode 13.
These at-rules apply styles contained within them, only if a condition is true.
The condition is contained within parentheses and contains a CSS property followed by a value, separated by a colon.
Continue reading %AtoZ CSS Screencasts: The CSS @supports Rule%
by Guy Routledge via SitePoint