You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[css-cascade] Make user-agent !important rules not overridable by transitions #14697
Currently, per CSS cascade, transition rules override all levels of the cascade, including user-agent !important rules.
That usually wouldn't be very problematic because those rules are (usually) not changing and thus not triggering transitions (though there are exceptions!).
But there's the issue that via web animations you can:
Retarget a transition from one element to another (via KeyframeEffect.target).
Override the keyframes of a random transition to transition another property.
This causes rules that are supposed to be invariant to break. Here's a test-case that shows a red backdrop incorrectly in Blink, because we force overlay: auto on a random element. Note that the element doesn't have to be a popover, but that just proves that it overrides the overlay: none !important:
Details
<!doctype html><style>#target{transition: all 0.5s allow-discrete;background: green;font-size:0px;width:100px;height:100px;position: absolute;top:0;left:0;&.tweak{/* Trigger a random transition */font-size:20px;}}#target::backdrop{position: fixed;background: red;inset:0;}</style><divid="target"></div><script>target.getBoundingClientRect();target.classList.add("tweak");letanim=target.getAnimations()[0];anim.effect.setKeyframes([{overlay: "auto"},{overlay: "auto"}]);anim.pause();</script>
I propose that we should swap the transitions cascade order with the UA !important origin. I've implemented this in Firefox (https://bugzilla.mozilla.org/show_bug.cgi?id=2081760) (though I just realized that the WPT I added passes in Blink / WebKit because the implement that with C++ magic, so I'll write another one that shows the issue in Blink / WebKit).
If there were transitions happening involving UA !important rules on one side, it might be a problem, but afaik we don't do that, so this makes sense to me.
Yeah, chatted with Emilio about this over TPAC. The reasons we set up the transition origin the way we did was reasonable, but it's fairly low-value and the potential abuse scenarios are much more important to worry about. I'm fine with moving transition origin down to nestle between author !important and UA !important, effectively just functioning as an author-level "most important".
One alternative option we could consider is to change the composite order when you modify the affected properties or target. This is similar to what happens when you dissociate the transition from its owning element: https://drafts.csswg.org/css-transitions-2/#cascade-level.
That said, I agree the only real use case for transitions on UA !important rules is just the overlay property, @josepharhar@mfreed7 . I feel like this is surprising even for authors that transitions override their own !important rules.
I feel like this is surprising even for authors that transitions override their own !important rules.
Well, note that before the Web Anim API, transitions could only be kicked off by CSS changes, and so they had to be above author !important rules precisely so they'd actually do something when the ending style was !important. Otherwise the !important value would win and the transition would kick off but do absolutely nothing visible! Remember that there's no phase where just the transition applies; it's always operating on top of the ending style.
Yeah that's fair, I forgot without web animations the worst you can do is delay your !important animations but it will always interrupt the previous transition and transition towards the new value.
nestle between author !important and UA !important
User !important is in there too. If we move transitions above user important, this API also makes it possible for authors to accidentally override a user important style? And if we move it below, user important styles can't transition. That may be fine, but it is a change that's not just related to UA styles.
Is there a solution that actually just keeps the API from doing things that shouldn't be allowed?
User !important is in there too. If we move transitions above user important, this API also makes it possible for authors to accidentally override a user important style?
Can't be done very accidentally (except if the site is malicious). However the implications of overriding user important stuff is "the user doesn't get its way", which is bad, but doesn't have security or so implications.
Note that transitions are already above user important, so the proposal is "no change for those".
And if we move it below, user important styles can't transition. That may be fine, but it is a change that's not just related to UA styles.
Since using !important is basically the only reasonable way of using user styles, that'd be sad, IMHO.
Is there a solution that actually just keeps the API from doing things that shouldn't be allowed?
Is there a solution that actually just keeps the API from doing things that shouldn't be allowed?
Not easily, no...
IMO this is the result of a mismatch of transition applying regardless of cascade level. It feels like we should require a !important transition to start a transition on !important styles. Then we could say that only !important transitions cascade about !important styles. Of course that's not what !important actually means on the transition properties.
Right, but that's not really enough, as long as you can retarget transitions across elements that match different UA rules, right?
It is, but it works pretty much the same way that your proposed solution here works, except that it generalizes how this works in a way that developers could use with !important styles as well.
I.e. if a transition's cascade level depends on the cascade level of the transition-duration property's value, then only a UA transition rule could start transitions on UA property changes (or lower), and only a developer !important transition rule could start transitions on !important values and lower.
I suppose we'd also have to say that developers can't read UA transitions and modify them - but that kind of makes sense and we wouldn't have any UA transitions yet so we could take our time figuring out this part.
I suppose we'd also have to say that developers can't read UA transitions and modify them - but that kind of makes sense and we wouldn't have any UA transitions yet so we could take our time figuring out this part.
Right, that's basically what would make that model sound, which is something like you can't setKeyframes() on a UA transition, or retarget it, or... It seems rather whack-a-mole-ish. Seems not worth the trouble IMHO.
Right, but I mentioned this in my edit, the important point is we don't have any UA !important transitions rules yet or else we couldn't do the original mitigation proposed in the OP. So we don't need to solve this yet, though I think trivial answers are either they are read only or they aren't even returned by getAnimations.
The CSS Working Group just discussed [css-cascade] Make user-agent `!important` rules not overridable by transitions, and agreed to the following:
RESOLVED: Transitions less important in cascade than UA !important rules, still more important than user !important rules
RESOLVED: Apply this change to all levels of cascade and republish where we can
The full IRC log of that discussion
<kbabbitt> emilio: user agent important rules are generally used both by HTML spec and other places
<kbabbitt> ... sometimes to enforce constraints
<kbabbitt> ... right now the cascade order of CSS transitions combined with the fact that you can retarget a transition using web animations arbitrarily breaks user important rules in ways they shouldn't be broken
<flackr> q+
<kbabbitt> ... means we cannot rely on that
<kbabbitt> ... lacking a strong use case for transitioning between UA important rules
<kbabbitt> ... I think there are use cases for user important
<kbabbitt> ... because that's the only sensible way of using user styles these days
<kbabbitt> ... but for UA important we don't have any use case for a legitimate transition
<kbabbitt> ... so I think simpler fix for now to allow specs and browsers to rely on UA important rules is to move transitions level down in cascade by 1
<kbabbitt> ... probably wider fixes we could consider
<kbabbitt> ... flackr mentioned keeping track of original cascade level of properties transitioning
<kbabbitt> ... still need to prevent retargeting and so on
<kbabbitt> ... tldr I think we can punt on those unless we're suddenly excited about transitioning UA important rules
<kbabbitt> ... propose moving transition level down by 1 in cascade, below UA important but above user importanbt
<kbabbitt> flackr: have a proposal that would generalize this to have a similar behavior for author !important vs regular author rules
<kbabbitt> ... but I think emilio's change is an okay first step
<kbabbitt> ... because that part of the cascade would be the same, even user !important transitions would be belkow UA stylesheet !important
<kbabbitt> ... my proposal woiuld allow UA stylesheet to set !important transition if we wanted a UA transition of some sort
<kbabbitt> ... but that's a follow up, I think it's fine to make immediate change
<kbabbitt> astearns: seems like a big change
<kbabbitt> astearns: am I wrong?
<kbabbitt> emilio: yes, in terms of user observable behavior it's not a big change, ened to be very intentional to transition a UA !important rule
<kbabbitt> ... only way to trigger a transition with non-UA important rules with user rules is if stylesheet has a transition to [missed]
<kbabbitt> ... or if creating a transition via web animations
<flackr> q+
<kbabbitt> ... not something I expect people to do
<kbabbitt> ... fwiw I made this change in Firefox we've been shipping a couple weeks, nothing has collapsed
<kbabbitt> ... in general this doesn't affect any other transition that wouldn't be covered by. ... can't transition [???]
<kbabbitt> flackr: forgot one other thing I wanted to mention
<kbabbitt> ... I think the overlay property is still UA-important
<kbabbitt> ... we were using transitions as a way to defer exit from top layer for exit animations of popovers and dialogs
<kbabbitt> emilio: joey proposed removing overlay propertyu, need something else but would not be a UA important thing
<kbabbitt> ... in terms of compat, UA may need to special case overlay for now
<kbabbitt> astearns: how many !important rules are there in UA stylesheets, and if we are going to have to do something else for that overlay case, are we constraining ourselves to not use !Important in UA stylesheets when transitions could be involved?
<kbabbitt> flackr: unless it stops being important, can't trigger a transition normal way
<kbabbitt> ... have to retarget or something
<kbabbitt> ... so I don't think it's too constraining but emilio can add more
<kbabbitt> emilio: was going to say basically that
<TabAtkins> Yeah, the *only* way to non-hackily kick a transition is when *leaving* a UA-important value.
<kbabbitt> ... if you have a UA important rule, only way to ... not generally used for things you would even imagine transitioning
<kbabbitt> ... usually if you need to make a UA rule !important, trying to override author
<kbabbitt> ... as flackr said, only way to trigger transition on UA rule is on something non-important that becomes important
<astearns> ack flackr
<kbabbitt> ... don't think we're putting ourselves into a corner
<kbabbitt> astearns: anyone else have comments?
<kbabbitt> emilio: Proposed resolution is to make transitions less important in cascade than UA !important rules, move them down one level
<miriam> seems weird, but only from a theoretical purity angle :)
<kbabbitt> ... interleaved between UA important and user important
<kbabbitt> astearns: any objections?
<kbabbitt> RESOLVED: Transitions less important in cascade than UA !important rules, still more important than user !important rules
<kbabbitt> fantasai: should we resolve to publish cascade 3 4 5 and 6?
<kbabbitt> astearns: that's a follow-on
<kbabbitt> emilio: resolution looks right
<kbabbitt> astearns: Proposed, make this edit and republish all the cascades?
<kbabbitt> ... make the edit for everything but cascade 3 to show we deliberatetly made this change?
<kbabbitt> fantasai: no, historical record is in list of changes, specs should be what we target
<kbabbitt> ... cascade 3 is rec so this would be an amendment
<kbabbitt> astearns: Propose to apply to all cascade specs and republish as needed
<kbabbitt> ChrisL: is cascade 3 published such that can be changed after rec or is this an errata?
<kbabbitt> fantasai: all recs can be changed after the fact, just can't add a feature
<kbabbitt> ... this is changing an existing feature, not adding one
<kbabbitt> RESOLVED: Apply this change to all levels of cascade and republish where we can
<fantasai> The whole point of Process 2020 was to enable fixing problems with existing specs
Activity
fantasai commentedon Nov 11, 2026
If there were transitions happening involving UA !important rules on one side, it might be a problem, but afaik we don't do that, so this makes sense to me.
tabatkins commentedon Nov 11, 2026
Yeah, chatted with Emilio about this over TPAC. The reasons we set up the transition origin the way we did was reasonable, but it's fairly low-value and the potential abuse scenarios are much more important to worry about. I'm fine with moving transition origin down to nestle between author !important and UA !important, effectively just functioning as an author-level "most important".
flackr commentedon Nov 11, 2026
One alternative option we could consider is to change the composite order when you modify the affected properties or target. This is similar to what happens when you dissociate the transition from its owning element: https://drafts.csswg.org/css-transitions-2/#cascade-level.
That said, I agree the only real use case for transitions on UA
!importantrules is just the overlay property, @josepharhar @mfreed7 . I feel like this is surprising even for authors that transitions override their own!importantrules.tabatkins commentedon Nov 11, 2026
Well, note that before the Web Anim API, transitions could only be kicked off by CSS changes, and so they had to be above author !important rules precisely so they'd actually do something when the ending style was !important. Otherwise the !important value would win and the transition would kick off but do absolutely nothing visible! Remember that there's no phase where just the transition applies; it's always operating on top of the ending style.
flackr commentedon Nov 11, 2026
Yeah that's fair, I forgot without web animations the worst you can do is delay your
!importantanimations but it will always interrupt the previous transition and transition towards the new value.emilio commentedon Nov 13, 2026
#14793 implements that.
mirisuzanne commentedon Nov 17, 2026
User !important is in there too. If we move transitions above user important, this API also makes it possible for authors to accidentally override a user important style? And if we move it below, user important styles can't transition. That may be fine, but it is a change that's not just related to UA styles.
Is there a solution that actually just keeps the API from doing things that shouldn't be allowed?
emilio commentedon Nov 17, 2026
Can't be done very accidentally (except if the site is malicious). However the implications of overriding user important stuff is "the user doesn't get its way", which is bad, but doesn't have security or so implications.
Note that transitions are already above user important, so the proposal is "no change for those".
Since using
!importantis basically the only reasonable way of using user styles, that'd be sad, IMHO.Not easily, no...
mirisuzanne commentedon Nov 17, 2026
I agree with preferring no change in relation to user styles.
flackr commentedon Nov 17, 2026
IMO this is the result of a mismatch of transition applying regardless of cascade level. It feels like we should require a
!importanttransition to start a transition on!importantstyles. Then we could say that only!importanttransitions cascade about!importantstyles. Of course that's not what!importantactually means on the transition properties.emilio commentedon Nov 17, 2026
Right, but that's not really enough, as long as you can retarget transitions across elements that match different UA rules, right?
flackr commentedon Nov 17, 2026
It is, but it works pretty much the same way that your proposed solution here works, except that it generalizes how this works in a way that developers could use with
!importantstyles as well.I.e. if a transition's cascade level depends on the cascade level of the transition-duration property's value, then only a UA transition rule could start transitions on UA property changes (or lower), and only a developer
!importanttransition rule could start transitions on!importantvalues and lower.I suppose we'd also have to say that developers can't read UA transitions and modify them - but that kind of makes sense and we wouldn't have any UA transitions yet so we could take our time figuring out this part.
emilio commentedon Nov 17, 2026
Right, that's basically what would make that model sound, which is something like you can't
setKeyframes()on a UA transition, or retarget it, or... It seems rather whack-a-mole-ish. Seems not worth the trouble IMHO.flackr commentedon Nov 17, 2026
Right, but I mentioned this in my edit, the important point is we don't have any UA
!importanttransitions rules yet or else we couldn't do the original mitigation proposed in the OP. So we don't need to solve this yet, though I think trivial answers are either they are read only or they aren't even returned by getAnimations.css-meeting-bot commentedon Nov 18, 2026
The CSS Working Group just discussed
[css-cascade] Make user-agent `!important` rules not overridable by transitions, and agreed to the following:RESOLVED: Transitions less important in cascade than UA !important rules, still more important than user !important rulesRESOLVED: Apply this change to all levels of cascade and republish where we canThe full IRC log of that discussion
<kbabbitt> emilio: user agent important rules are generally used both by HTML spec and other places<kbabbitt> ... sometimes to enforce constraints
<kbabbitt> ... right now the cascade order of CSS transitions combined with the fact that you can retarget a transition using web animations arbitrarily breaks user important rules in ways they shouldn't be broken
<flackr> q+
<kbabbitt> ... means we cannot rely on that
<kbabbitt> ... lacking a strong use case for transitioning between UA important rules
<kbabbitt> ... I think there are use cases for user important
<kbabbitt> ... because that's the only sensible way of using user styles these days
<kbabbitt> ... but for UA important we don't have any use case for a legitimate transition
<kbabbitt> ... so I think simpler fix for now to allow specs and browsers to rely on UA important rules is to move transitions level down in cascade by 1
<kbabbitt> ... probably wider fixes we could consider
<kbabbitt> ... flackr mentioned keeping track of original cascade level of properties transitioning
<kbabbitt> ... still need to prevent retargeting and so on
<kbabbitt> ... tldr I think we can punt on those unless we're suddenly excited about transitioning UA important rules
<kbabbitt> ... propose moving transition level down by 1 in cascade, below UA important but above user importanbt
<kbabbitt> flackr: have a proposal that would generalize this to have a similar behavior for author !important vs regular author rules
<kbabbitt> ... but I think emilio's change is an okay first step
<kbabbitt> ... because that part of the cascade would be the same, even user !important transitions would be belkow UA stylesheet !important
<kbabbitt> ... my proposal woiuld allow UA stylesheet to set !important transition if we wanted a UA transition of some sort
<kbabbitt> ... but that's a follow up, I think it's fine to make immediate change
<kbabbitt> astearns: seems like a big change
<kbabbitt> astearns: am I wrong?
<kbabbitt> emilio: yes, in terms of user observable behavior it's not a big change, ened to be very intentional to transition a UA !important rule
<kbabbitt> ... only way to trigger a transition with non-UA important rules with user rules is if stylesheet has a transition to [missed]
<kbabbitt> ... or if creating a transition via web animations
<flackr> q+
<kbabbitt> ... not something I expect people to do
<kbabbitt> ... fwiw I made this change in Firefox we've been shipping a couple weeks, nothing has collapsed
<kbabbitt> ... in general this doesn't affect any other transition that wouldn't be covered by. ... can't transition [???]
<kbabbitt> flackr: forgot one other thing I wanted to mention
<kbabbitt> ... I think the overlay property is still UA-important
<kbabbitt> ... we were using transitions as a way to defer exit from top layer for exit animations of popovers and dialogs
<kbabbitt> emilio: joey proposed removing overlay propertyu, need something else but would not be a UA important thing
<kbabbitt> ... in terms of compat, UA may need to special case overlay for now
<kbabbitt> astearns: how many !important rules are there in UA stylesheets, and if we are going to have to do something else for that overlay case, are we constraining ourselves to not use !Important in UA stylesheets when transitions could be involved?
<kbabbitt> flackr: unless it stops being important, can't trigger a transition normal way
<kbabbitt> ... have to retarget or something
<kbabbitt> ... so I don't think it's too constraining but emilio can add more
<kbabbitt> emilio: was going to say basically that
<TabAtkins> Yeah, the *only* way to non-hackily kick a transition is when *leaving* a UA-important value.
<kbabbitt> ... if you have a UA important rule, only way to ... not generally used for things you would even imagine transitioning
<kbabbitt> ... usually if you need to make a UA rule !important, trying to override author
<kbabbitt> ... as flackr said, only way to trigger transition on UA rule is on something non-important that becomes important
<astearns> ack flackr
<kbabbitt> ... don't think we're putting ourselves into a corner
<kbabbitt> astearns: anyone else have comments?
<kbabbitt> emilio: Proposed resolution is to make transitions less important in cascade than UA !important rules, move them down one level
<miriam> seems weird, but only from a theoretical purity angle :)
<kbabbitt> ... interleaved between UA important and user important
<kbabbitt> astearns: any objections?
<kbabbitt> RESOLVED: Transitions less important in cascade than UA !important rules, still more important than user !important rules
<kbabbitt> fantasai: should we resolve to publish cascade 3 4 5 and 6?
<kbabbitt> astearns: that's a follow-on
<kbabbitt> emilio: resolution looks right
<kbabbitt> astearns: Proposed, make this edit and republish all the cascades?
<kbabbitt> ... make the edit for everything but cascade 3 to show we deliberatetly made this change?
<kbabbitt> fantasai: no, historical record is in list of changes, specs should be what we target
<kbabbitt> ... cascade 3 is rec so this would be an amendment
<kbabbitt> astearns: Propose to apply to all cascade specs and republish as needed
<kbabbitt> ChrisL: is cascade 3 published such that can be changed after rec or is this an errata?
<kbabbitt> fantasai: all recs can be changed after the fact, just can't add a feature
<kbabbitt> ... this is changing an existing feature, not adding one
<kbabbitt> RESOLVED: Apply this change to all levels of cascade and republish where we can
<fantasai> The whole point of Process 2020 was to enable fixing problems with existing specs