Origins and competing rules
Definition and purpose
The cascade chooses a declaration for each property on each element. User-agent styles are supplied by the browser, user styles by the visitor, and author styles by the site. In ordinary normal declarations, author styles outrank user styles, which outrank user-agent styles.
Override a browser default
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style>#a { font-weight: normal; }</style> </head> <body> <h2 id="a">Notice</h2> <h2 id="b">Other</h2> </body></html>Only the first heading loses default bold weight.
Syntax and mental model
First filter out rules that do not match or are in inactive conditions. Compare origin and importance before selector specificity; layers and other cascade stages are covered later. A browser default is a real rule or initial value, not an inherited copy of the author stylesheet. These examples use author styles and browser defaults, not a simulated user-origin stylesheet.
Filter competing rules
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> p { color: navy; } @media not all { #a { color: red; } } .note { color: green; } </style> </head> <body> <p id="a" class="note">Notice</p> <p id="b">Other</p> </body></html>The inactive media rule never enters the competition; the matching class wins for the note.
Common mistakes
Do not assume a second style element is a different origin. Both are author styles. Do not remove default focus feedback just to override browser styles.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Pseudo-elements and generated boxes. Next lesson: Specificity and source order.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Origins and competing rules — knowledge check
Five questions on origins and competing rules.
Which origin supplies browser default rules?
Which ordinary normal origin wins over a user-agent declaration?
What happens to a nonmatching rule?
Two style elements in the page belong to which origin?
Why does @media not all prevent a rule from winning?