Skip to content

[css-conditional-4] Need a way in CSS to test for support of HTML features #9746

Open
@jensimmons

Description

@jensimmons

There should be a way to feature detect support for an HTML attribute, HTML element and other things in HTML.

For instance, the switch attribute is new to HTML. It turns a checkbox form control into a native switch, in a progressively enhanced fashion.

Authors will likely want to style their switch with custom styles, while still supporting the checkbox fallback. If they apply styles without writing conditional code, the checkbox is ruined.

This is one idea of how it could work...

@supports selector(input[switch]) {
 /* Would like to put custom switch styles here, so they only apply conditionally. */
}

...but that doesn't work... because it always returns true. The selector is understood by CSS, even when it's not supported in HTML.

How can we provide a mechanism to CSS for testing support of HTML features?

Here's a demo of switch, with custom styles that should be applied conditionally.
https://codepen.io/jensimmons/pen/eYXYZWr?editors=1100

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions