Course contentsShow
← Web Development
Lesson 133 of 2,9823. CSS FundamentalsFree lesson

The Cascade and Source Order

Understand how source order breaks ties when specificity is equal between rules.

The Cascade and Source Order

What you'll learn: How CSS decides which rule wins when two conflicting styles have the exact same specificity.

When Specificity Isn't Enough

You've learned that CSS uses specificity to determine which style rule applies when multiple rules target the same element. But what happens when two rules have identical specificity? This is where source order comes into play.

The Last Rule Wins

When competing rules have equal specificity, CSS applies the rule that appears last in your stylesheet. Think of it like a painting: if you paint the same spot twice with equal force, only the last stroke shows.

p {
  color: blue;
}

p {
  color: red;
}

Both rules use a type selector (0-0-1 specificity). Since they're equal, the browser applies color: red because it comes last.

This works across multiple stylesheets too:

<link rel="stylesheet" href="first.css">
<link rel="stylesheet" href="second.css">

If both files contain .button { color: blue; } and .button { color: green; } respectively with identical specificity, the rule from second.css wins because it loads last.

Why This Matters

Understanding source order helps you:

  • Debug why a style isn't applying (something later might be overriding it)
  • Organize your CSS logically (put defaults first, overrides last)
  • Avoid unnecessarily increasing specificity just to "force" a style

Key Takeaway: When specificity is equal, the rule that appears last in source order wins—this is CSS's tiebreaker mechanism.