iananananan iananananan - 1 month ago 16
CSS Question

In which order do CSS stylesheets override?

In an HTML header, I've got this:

<link href="styles.css" rel="stylesheet" type="text/css"/>
<link href="master.css" rel="stylesheet" type="text/css"/>

is my page-specific sheet.
is a sheet I use on each of my projects to override browser defaults. Which of these stylesheets takes priority?
Example: first sheet contains specific

body { margin:10px; }

And associated borders, but the second contains my resets of

html, body:not(input="button") {
margin: 0px;
padding: 0px;
border: 0px;

In essence, does the cascading element of CSS work the same in terms of stylesheet references as it does in typical CSS functions? Meaning that the last line is the one displayed?


The rules for CSS rule cascading are complex -- rather than trying to paraphrase them badly, I'll simply refer you to the spec:


In short: more specific rules override more general ones. Specificity is defined based on how many IDs, classes, and element names are involved, as well as whether the !important declaration was used. When multiple rules of the same "specificity level" exist, whichever one appears last wins.