0.2.0 • Published 8 months ago

supports-css v0.2.0

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

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 <html> 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

Feature ClassGlobal NameTest Condition
at-containerAtContainerwindow.CSSContainerRule
at-container-style-propertiesAtContainerStyleProperties* See explanation
at-counter-styleAtCounterStylewindow.CSSCounterStyleRule
at-layerAtLayerwindow.CSSLayerBlockRule
at-propertyAtPropertywindow.CSSPropertyRule
at-scopeAtScopewindow.CSSScopeRule
anchor-positioningAnchorPositioningCSS.supports('anchor-name: --a')
color-functionColorFunctionCSS.supports('color: color(srgb 0 0 1)')
color-mixColorMixCSS.supports('color: color-mix(in lch, white, black)')
container-unitsContainerUnitsCSS.supports('width: 1cqi')
dynamic-viewport-unitsDynamicViewportUnitsCSS.supports('width: 1dvi')
hasHasCSS.supports('selector(:has(+ *))') (Possible false positive in Firefox 112)
houdini-paint-apiHoudiniPaintApiwindow.CSS.paintWorklet
individual-transformsIndividualTransformsCSS.supports('transform: scale(1)')
logical-propertiesLogicalPropertiesCSS.supports('border-start-start-radius: 1px')
media-range-syntaxMediaRangeSyntaxwindow.matchMedia('(width >= 1px)')
nestingNestingCSS.supports('selector(& a)')
nth-of-sNthOfSCSS.supports('selector(:nth-child(1 of .a))')
overscroll-behaviorOverscrollBehaviorCSS.supports('overscroll-behavior: none')
relative-color-syntaxRelativeColorSyntaxCSS.supports('color: rgb(from red r g b / 1%)')
scroll-timelineScrollTimelineCSS.supports('scroll-timeline-name: --a')
subgridSubgridCSS.supports('grid-template-rows: subgrid')
text-box-trimTextBoxTrimCSS.supports('text-box-trim: both')
trigonometryTrigonometryCSS.supports('width: calc(1px * cos(1deg))')
user-invalidUserInvalidCSS.supports('selector(:user-invalid)')
user-validUserValidCSS.supports('selector(:user-valid)')
view-timelineViewTimelineCSS.supports('view-timeline-name: --a'),
view-transitionsViewTransitionswindow.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

Created by Stephanie Eckles, author of ModernCSS.dev, SmolCSS.dev, and other front-end dev resources.

0.2.0

8 months ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago