You can’t override !important user agent CSS declarations (#tilPost)

Cascade Layers are around the corner, and Una took this CSS revolution as an opportunity to look into the CSS cascade in a short YouTube video.
While watching the video, I learned something new about the !important CSS keyword. Befo…


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis

Cascade Layers are around the corner, and Una took this CSS revolution as an opportunity to look into the CSS cascade in a short YouTube video.

While watching the video, I learned something new about the !important CSS keyword. Before getting into important, though, let's look at where styles can come from. Three different CSS origins define a website's look and feel:

  • the browser default styles defined in user agent stylesheets
  • user-defined styles to customize a website defined in user stylesheets
  • web page styling defined and linked in author stylesheets

User stylesheets don't seem to be a thing anymore. Chrome disallows them, and Firefox plans to phase them out, hiding the feature behind a development flag.

How do these three origins affect each other? You can override user agent stylesheet declarations with your author styles. And indeed, you do that every day when you write your CSS. Author styles override user styles, which override user agent styles.

But here's the thing: this cascade order is inverted for !important CSS properties. Important user agent styles override important user styles, which override important author styles.

You can't override !important declarations coming from your browser's user agent stylesheet. 😲

Una shared a Dev Doodle highlighting the concept on Instagram. 👇

I went straight into the Firefox user agent stylesheet to see what's !important in there.

audio:not([controls]) {
  display: none !important;
}

spacer {
  position: static ! important;
  float: none ! important;
}

iframe:fullscreen {
  border: none !important;
  padding: unset !important;
}

Luckily, there aren't many !important declarations in Firefox's user agent stylesheet. And the few I found include legacy things mainly (what's a spacer?). 🤷‍♂️

Nevertheless, that's a good-to-know fact. If you want to learn more about !important or want to get a taste of Cascade Layers, check Una's video.


Reply to Stefan


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis


Print Share Comment Cite Upload Translate Updates
APA

Stefan Judis | Sciencx (2022-02-04T23:00:00+00:00) You can’t override !important user agent CSS declarations (#tilPost). Retrieved from https://www.scien.cx/2022/02/04/you-cant-override-important-user-agent-css-declarations-tilpost/

MLA
" » You can’t override !important user agent CSS declarations (#tilPost)." Stefan Judis | Sciencx - Friday February 4, 2022, https://www.scien.cx/2022/02/04/you-cant-override-important-user-agent-css-declarations-tilpost/
HARVARD
Stefan Judis | Sciencx Friday February 4, 2022 » You can’t override !important user agent CSS declarations (#tilPost)., viewed ,<https://www.scien.cx/2022/02/04/you-cant-override-important-user-agent-css-declarations-tilpost/>
VANCOUVER
Stefan Judis | Sciencx - » You can’t override !important user agent CSS declarations (#tilPost). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/02/04/you-cant-override-important-user-agent-css-declarations-tilpost/
CHICAGO
" » You can’t override !important user agent CSS declarations (#tilPost)." Stefan Judis | Sciencx - Accessed . https://www.scien.cx/2022/02/04/you-cant-override-important-user-agent-css-declarations-tilpost/
IEEE
" » You can’t override !important user agent CSS declarations (#tilPost)." Stefan Judis | Sciencx [Online]. Available: https://www.scien.cx/2022/02/04/you-cant-override-important-user-agent-css-declarations-tilpost/. [Accessed: ]
rf:citation
» You can’t override !important user agent CSS declarations (#tilPost) | Stefan Judis | Sciencx | https://www.scien.cx/2022/02/04/you-cant-override-important-user-agent-css-declarations-tilpost/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.