A partial archive of discourse.wicg.io as of Saturday February 24, 2024.

[Proposal] Lifting ‘user’ declarations above ‘author’ in the CSS cascade

silverwind
2018-01-05

The CSS cascade includes user origin declarations which are rules provided by the user itself, for example user stylesheets applied by web extensions. The current priority of user over author origins is specced as follows:

  • user !imporant > author !important > author > user

A author’s declaration wins over a same-specificity user declaration except when !important is involved at which point the priority is reversed. This issue has in the past lead to browser extensions to insert their userstyles as the last author sheets which introduces the issue that two author sheets (the page’s own and the userstyle) have to fight for specificity which is a source of issues.

I propose that the ordering of user origin sheets to be put above author sheets like this:

  • user !imporant > author !important > user > author

This new ordering would banish having to use !important everywhere in userstyles and would also remove the necessity to fight for specificity with the target page’s styles.

Note that user origin stylesheets are a mostly unused concept today, only Firefox >= 53 allows web extensions to insert such sheets, Chrome will likely get the API option on tabs.insertCSS for it in 66, but until then, extensions can only insert author origin stylesheets.

Some more detail about the behaviour of extensions here. It’s a pretty old page, but most info on there is still valid today.

silverwind
2018-01-05

Interesting fact: The CSS1 cascading order specifies

the author’s style sheets override the reader’s style sheet

This order was then reversed in the CSS2 spec, but only for !important declarations. I think it’s time to be consistent also do it for normal declarations.

SoniEx2
2018-01-06

Does font style (configurable in browser) set what kind of style?

patrick_h_lauke
2018-01-09

The current ordering does allow users to set styles as default unless the author has explicitly set other styles. i.e. it allows a sort of “complementary” styling that works together with author styles. Then, if a user absolutely wants to set something, they make it “!important”. That reduces the likelihood of user styles overriding some author-set styles that would otherwise result in potentially completely broken end results.

chaals
2018-01-10

I did a lot of work to make the change between CSS1 and CSS2. Chris Wilson can explain better than I why it wasn’t nearly as useful as we had hoped, but more importantly I think it would be a mistake to do this for the reasons Patrick outlined.