CSS.supports Probes Feature Support
CSS.supports probes a single declaration with two arguments or a full @supports condition with one, driving progressive enhancement decisions.
Code
// CSS.supports 探测浏览器是否支持某条声明或完整的 @supports 条件
console.log(CSS.supports('display', 'grid'));
console.log(CSS.supports('display', 'flex'));
console.log(CSS.supports('--accent', 'rebeccapurple')); // 自定义属性声明同样可探测
// 双参形式测"属性: 值";单参形式测完整条件语法
console.log(CSS.supports('(display: grid) and (backdrop-filter: blur(2px))'));
console.log(CSS.supports('display', 'turbowarp')); // 不存在的值 → false
// 特性探测驱动渐进增强:支持才启用玻璃效果,否则走实色降级
function glassSupported() {
return CSS.supports('backdrop-filter', 'blur(4px)');
}
const toolbar = document.createElement('nav');
toolbar.classList.add(glassSupported() ? 'toolbar-glass' : 'toolbar-solid');
console.log('glass:', glassSupported(), '->', toolbar.className);CSS.supports Probes Feature Support: the mechanics
CSS.supports Probes Feature Support comes down to the function glassSupported.
Watch out for
- No third-party code is loaded at any point while this runs.
- A browser is the runtime here:
documentare not available in Node.
Applying it
Signature: function glassSupported()
The run emits 1 labeled section — glass: — one per step.
Statements that matter
return CSS.supports('backdrop-filter', 'blur(4px)');
Interactive Tools for This Topic
Aspect Ratio CalculatorSimplify a width-to-height ratio, show its decimal value, and derive a matching height for a new width.Border Radius PreviewPreview four-corner border-radius values on a live box and copy the generated shorthand border-radius CSS declaration.Box Shadow GeneratorBuild CSS box-shadow values with offset, blur, spread, color, opacity, and inset controls, with a live preview of the result.CSS Color Name LookupTranslate between CSS keyword color names and hex values with RGB and HSL conversions, exact name matching, and nearest-color suggestions.
FAQ
- Does CSS.supports Probes Feature Support run in plain Node.js?
- No — it touches `document`, which exist only in the browser. Run it in a page (or the DevTools console) instead of a bare Node process.
Report a problem with this exampleOpens a pre-filled issue on GitHub.