I was reading a decent article here on this topic: http://www.plus2net.com/html_tutorial/css-types.php It came out highest ranked by Google for the search term css style sheets priorities. However I think the site misinforms you and is incomplete! Can someone confirm my suspicions?
1) User Defined style is second lowest priority. In order to override other styles with it, you need to use !important to move it to highest. 2) It fails to mention the relative priorities of <link> versus @import and @import within <link>
A more precise ordering would be (1 wins over 2 etc) :
- User defined (browser prefs !important - [not Google Chrome!])
- Inline style sheet (style attribute on HTML node)
- Internal style sheet (<style> in <head>)
- External style sheet (@import)
- External style sheet (<link>)
- External style sheet (@import inside <link>)
- User defined - (browser prefs - [not Google Chrome!])
- Browser default - (shipped with browser)
Michael Bowers Pro CSS & HTML Design Patterns is a good source for this too. But it fails to mention inline.
Is there anything else missing?
PS: I was inferring !important was missing from 2-8. So User defined appears twice. Once with important, the second time without it. So user defined is in essence second lowest. The !important can naturally be applied at any level.
!important
can act as a trump card at any level in the hierarchy. As far as "what's missing", probably a discussion of selector specificity. That's caught me up on a few occasions. – Mudguard!important
, inline styles take the highest precedence. – Slavin