Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Window.CSS.supports — detect CSS feature support

Use JavaScript to test whether the browser supports a specific CSS property–value pair or satisfies a CSS support condition before choosing an enhanced behavior.

Version: ECMAScript 2024 and the current web platform; runtime support varies

Syntax

window.CSS.supports(propertyName, value)
window.CSS.supports(supportCondition)

Window.CSS.supports refers to the supports method on the browser window’s CSS namespace. In page code, call window.CSS.supports() or use CSS.supports() if nothing shadows the global CSS name. It is a Web API, not part of ECMAScript 2024 and not a static method on the Window constructor.

With two arguments, pass a CSS property name and value as separate strings, as in CSS.supports("font-size", "1rem"). Use the CSS spelling (font-size, not fontSize). With one argument, pass only the condition, without @supports, such as "(font-size: 1rem)" or "selector(:has(a))". Combine conditions with CSS keywords and, or, and not, not JavaScript’s &&, ||, and ! inside the string.

A result of true means the support test passed in that browser. An unsupported pair or a malformed condition returns false. The method does not apply styles or check whether a selector matches any element. Even true does not guarantee bug-free rendering.

Do not assume this API exists outside browser pages, such as in workers or on servers. Before calling it, you can check typeof globalThis.CSS?.supports === "function". A missing method and a false result are different, but both can lead to the same fallback. If the condition only controls styles, use the @supports at-rule directly in CSS.

Examples

<!doctype html>
<meta charset="utf-8">
<title>CSS.supports example</title>
<script>
  console.log(window.CSS.supports("color", "red"));
  console.log(window.CSS.supports("color", "123px"));
  console.log(window.CSS.supports("(color: red) and (color: blue)"));
</script>

Result

true
false
true

In a browser page console that exposes the method, expect `true`, `false`, and `true`, in that order. The last condition tests whether both declarations are supported, not whether both colors are applied at once.

Related lessons

  • JavaScript · Lesson 37 · Advanced · Version: 4

Sources