Does the order of css stylesheet definitions matter?

If the selectors are identical, the last loaded takes precedence, just as if you declared the same class twice in the same stylesheet.


There is a defined cascade in which the styles are sorted and applied. When declarations have the same importance (weight), origin and specificity then the latter declaration wins. Most answers cover importance and specificity here but not origin.

Here are some very good slides about CSS Cascades. (Overview all resources)


If I use this, can I trust that the values in the default stylesheet will be overridden by the values from the other stylesheet? I am using class selectors and will override values when the names match.

The answer is "yes", as you noted, when the selectors on the second sheet are identical to the first.

The use of !important will be the exception, so avoid it, as you also noted.


If you have defined style for a selector in more than one css file, the style from last loaded CSS file will be taken

Tags:

Css

Stylesheet