Code Monkey home page Code Monkey logo

supportscss's Introduction

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 Class Global Name Test Condition
at-container AtContainer window.CSSContainerRule
at-container-style-properties AtContainerStyleProperties * See explanation
at-counter-style AtCounterStyle window.CSSCounterStyleRule
at-layer AtLayer window.CSSLayerBlockRule
at-property AtProperty window.CSSPropertyRule
at-scope AtScope window.CSSScopeRule
anchor-positioning AnchorPositioning CSS.supports('anchor-name: --a')
color-function ColorFunction CSS.supports('color: color(srgb 0 0 1)')
color-mix ColorMix CSS.supports('color: color-mix(in lch, white, black)')
container-units ContainerUnits CSS.supports('width: 1cqi')
dynamic-viewport-units DynamicViewportUnits CSS.supports('width: 1dvi')
has Has CSS.supports('selector(:has(+ *))')
(Possible false positive in Firefox 112)
houdini-paint-api HoudiniPaintApi window.CSS.paintWorklet
individual-transforms IndividualTransforms CSS.supports('transform: scale(1)')
logical-properties LogicalProperties CSS.supports('border-start-start-radius: 1px')
media-range-syntax MediaRangeSyntax window.matchMedia('(width >= 1px)')
nesting Nesting CSS.supports('selector(& a)')
nth-of-s NthOfS CSS.supports('selector(:nth-child(1 of .a))')
overscroll-behavior OverscrollBehavior CSS.supports('overscroll-behavior: none')
relative-color-syntax RelativeColorSyntax CSS.supports('color: rgb(from red r g b / 1%)')
scroll-timeline ScrollTimeline CSS.supports('scroll-timeline-name: --a')
subgrid Subgrid CSS.supports('grid-template-rows: subgrid')
text-box-trim TextBoxTrim CSS.supports('text-box-trim: both')
trigonometry Trigonometry CSS.supports('width: calc(1px * cos(1deg))')
user-invalid UserInvalid CSS.supports('selector(:user-invalid)')
user-valid UserValid CSS.supports('selector(:user-valid)')
view-timeline ViewTimeline CSS.supports('view-timeline-name: --a'),
view-transitions ViewTransitions 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

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

supportscss's People

Contributors

5t3ph avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.