SupportsCSS

Live, in-browser detection of modern CSS support for selectors, features, a...

README

SupportsCSS


Live, in-browser detection of modern CSS support for selectors, features, and at-rules. Applies support-based classes, exposes a results object, and allows custom tests.


Inspired by the legacy of Modernizr, this script evaluates a user's browser for cutting-edge modern CSS support beyond the capabilities of@supports.

- Classes are added to `` as either `supports-[feature]` or `no-[feature]`, allowing easier progressive enhancement and build strategies
- Checks for selectors like :has(), properties like text-box-trim, features like relative color syntax, and at-rules like @layer - see full test suite
- Allows adding custom tests
- Exposes a results object to iterate over detected support, as well as individual results for quick conditional checks in JS

SupportsCSS is _not_ a polyfill, it is only feature detection. Continue using tools like PostCSS or LightningCSS for prefixing and other features like syntax lowering. SupportsCSS is a layer on top of those tools.


Installation & Usage


Review the full docs at SupportsCSS.dev.

Test Suite


FeatureGlobalTest
|---|---|---|
at-containerAtContainer`window.CSSContainerRule`
at-container-style-propertiesAtContainerStyleProperties*
at-counter-styleAtCounterStyle`window.CSSCounterStyleRule`
at-layerAtLayer`window.CSSLayerBlockRule`
at-propertyAtProperty`window.CSSPropertyRule`
at-scopeAtScope`window.CSSScopeRule`
anchorAnchor`CSS.supports('left:
color-functionColorFunction`CSS.supports('color:
color-mixColorMix`CSS.supports('color:
container-unitsContainerUnits`CSS.supports('width:
dynamic-viewport-unitsDynamicViewportUnits`CSS.supports('width:
hasHas`CSS.supports('selector(:has(+
houdini-paint-apiHoudiniPaintApi`window.CSS.paintWorklet`
individual-transformsIndividualTransforms`CSS.supports('transform:
logical-propertiesLogicalProperties`CSS.supports('border-start-start-radius:
media-range-syntaxMediaRangeSyntax`window.matchMedia('(width
nestingNesting`CSS.supports('selector(&
nth-of-sNthOfS`CSS.supports('selector(:nth-child(1
overscroll-behaviorOverscrollBehavior`CSS.supports('overscroll-behavior:
relative-color-syntaxRelativeColorSyntax`CSS.supports('color:
scroll-timelineScrollTimeline`CSS.supports('scroll-timeline-name:
subgridSubgrid`CSS.supports('grid-template-rows:
text-box-trimTextBoxTrim`CSS.supports('(leading-trim:
trigonometryTrigonometry`CSS.supports('width:
view-timelineViewTimeline`window.ViewTimeline`
view-transitionsViewTransitions`window.ViewTransition`


How were these features selected?


Features were selected based on:

- @supports limitations
- instability of the spec
- freshness to the language
- impact on CSS architecture
- impact on progressive enhancement

Colophon