Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading CSS Style Sheet with Feature Queries #6064

Open
tntrifonov opened this issue Oct 15, 2020 · 1 comment
Open

Loading CSS Style Sheet with Feature Queries #6064

tntrifonov opened this issue Oct 15, 2020 · 1 comment

Comments

@tntrifonov
Copy link

Introduction

Loading a CSS file conditionally is a powerful feature. It allows separating styles in different files for each use case.

It's currently possible to load a style sheet using media queries:

<link rel="stylesheet" media='screen and (max-width: 768px)' href="site.css"/>

This uses the <link> element's media attribute. It detects screen width and acts accordingly.

The Problem

However, we can't detect feature support. This seems like the perfect place for it, yet we can't detect browser features and load the correct style sheet?

Proposal

I propose a new attribute for the <link> and <style> elements with the name supports:

<link rel="stylesheet" supports='(display: grid)' href="site-modern.css"/>

This new attribute supports copies the functionality of the media attribute, however it works with feature queries instead of media queries.

Use Case

Ability to load styles conditionally based on browser features allows developers to split CSS styles into files - this means they can have a modern.css and old-browsers.css, the same way they can have a mobile.css and desktop.css with media queries.

@Crissov
Copy link

Crissov commented Mar 12, 2024

The big difference between media queries and support queries is that MQ are specified by the CSSWG in a language-agnostic way, while SQ are inherently tied to CSS and therefore are misplaced in an HTML attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants