Email or username:

Password:

Forgot your password?
Noah Liebman

I blug about #css again. Preventing an `!important` user agent style from kicking in with an infinite-duration transition noahliebman.net/2024/08/beatin

```css
input {
  /* prevent anything that tries to change this from ever getting there */
  transition:
    color calc(infinity * 1s) step-end,
    background-color calc(infinity * 1s) step-end;

  /* style the field as normal */
  background-color: transparent;
  color: CanvasText;
}
```
13 comments
Paul Tichonczuk

@noleli white kind of performance penalty would this incur?

Noah Liebman

@paultk interesting question. I donā€™t know, but considering how efficient CSS animations generally are, how infrequently this scenario might come up, and possible optimizations of `step` timing functions, I assume itā€™s quite safe

Amadeus Maximilian

@noleli Iā€™m assuming this works, because the user specified styles get applied first, because the !important of the user agent stylesheet makes it kick in last? And thatā€™s how the initial state of the transition is set?

I never thought of !important styles being applied *after* regular ones in a ā€œtimeā€ sense. šŸ˜…

Noah Liebman

@amxmln itā€™s not a time thing, but a precedence thing. The cascade (origin, specificity, layers, etc.) determines which styles are applied. A feature of the cascade is that active transitions take precedence over everything else. Essentially itā€™s telling something ā€œtake forever to get to your destination even if your destination is really high priority.ā€

Amelia Bellamy-Royds

@noleli @amxmln Ah, but Amadeus has a point: In order to have a transition, it's not enough to have multiple styles competing in the cascade. There has to be an initial time when those styles didn't apply.

Unless you use the new @ starting-style rule, but I don't think that's well supported yet.

Noah Liebman

@AmeliaBR @amxmln thatā€™s a good point. in this case, author styles are applied initially, and only once someone tries to autofill and the proprietary pseudoclass gets applied does it (try to) go to the !important UA styles. I should clarify that in my post, because this trick only works under those circumstances.

Amelia Bellamy-Royds

@noleli @amxmln Also, separate issue: but I hope you have a real good reason for overriding user agent !important styles if you're using this in practice & not as just a weird CSS trick.

Noah Liebman

@AmeliaBR totally. I may have missed it, but I didnā€™t see in the spec that a UA must make clear that a field has been autofilled. That said, I could imagine it being a security concern if it doesnā€™t. Certainly warrants more discussion with the design team.

Amadeus Maximilian

@noleli @AmeliaBR thank you for clarifying. šŸ˜Š I think I got it now. šŸ‘

meduz'

@noleli Ha ha ha, super nice trick. I didnā€™t know about `infinity` for CSS transition.

lencioni

@noleli would it be a bit cleaner to set the transition-delay to infinity instead of the transition-duration? Of course the result should be the same but that would remove the need to specify the timing function I think.

Noah Liebman

@lencioni afk, but I bet youā€™re right. Good call!

Go Up