CSS chapters

Chapter 13 of 17

The cascade and debugging

Try this in our CSS Compiler →

The idea

When valid declarations compete, origin, importance, cascade layers and specificity affect which wins; source order resolves remaining ties. A crossed-out declaration in DevTools may be valid but overridden. An invalid declaration is a different failure. Avoid solving every conflict with !important.

Worked example

h1 { color: teal; }
h1 { color: navy; }
/* Same selector and priority: the later declaration wins. */

What to check

The heading is navy because these two rules have equal priority. A more specific selector can win even when it appears earlier.

Practice task

Inspect a heading's computed colour. Identify the winning selector before deleting or adding any rule.

Check your understanding

Explain the result in your own words before changing the example. Change one thing at a time, compare the result with your prediction, and keep the version that demonstrates the concept clearly.

Try it yourself

Output
Ctrl/Cmd+Enter runs · Ctrl/Cmd+S downloads the project · Local auto-save is always on