Specificity and the cascade

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Specificity and the cascade

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which selector type has the highest specificity score?
A Class selector (.class)
B ID selector (#id)
2. Two rules target the same element with equal specificity. Which rule applies?
A The rule written last in the stylesheet
B The rule written first in the stylesheet
3. Does !important override an inline style?
A Yes — !important beats inline styles
B No — inline styles always win
4. Which rule wins: 'p { color: blue; }' or '.text { color: red; }'?
A p { color: blue; }
B .text { color: red; }
5. An element selector and a class selector both target the same element. Which wins?
A Class selector
B Element selector

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1#hero { color: red; } AForces this declaration to override all other rules, including IDs
2color: blue !important; B!important is misspelled — the browser ignores the keyword
3Cascade source order tiebreaker Cp { color: black; } p { color: red; }
4Class selector specificity beats element selector DID selector — highest specificity among selectors
5p { color: black } EMissing semicolon after the declaration value
6.box { color: red !importent; } F.note { color: green; }

Definitions

specificity

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
p { _____ red; }
2.
____ { color: blue; }
3.
______ { color: green; }
4.
h1, p { _________ 16px; }
5.
body { color: black __________; }

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A .box { color: green }
B .note { color: blue; }
C #main { color: red; }
Question 2
A p { color: black; }
B .intro { colour: blue; }
C #hero { color: red; }
Question 3
A h2 { font-size: 24px; }
B .title { font-size: 20px; }
C #hero { font-size 32px; }
Question 4
A body { background: white; }
B p { color: gray; }
C .box { color: green; }
D h1 { color: black !importnt; }
Question 5
A #header { color: navy; }
B p { color: black; }
C .nav { color: teal; }
D h2 { font-size: 20px; }
E span color: gray; }

Answer Key

Specificity and the cascade
Section A: Quick Questions
Q1
B — ID selector (#id)
Q2
A — The rule written last in the stylesheet
Q3
A — Yes — !important beats inline styles
Q4
B — .text { color: red; }
Q5
A — Class selector
Section B: Match the Pairs
Q1
#hero { color: red; } → ID selector — highest specificity among selectors
Q2
color: blue !important; → Forces this declaration to override all other rules, including IDs
Q3
Cascade source order tiebreaker → p { color: black; } p { color: red; }
Q4
Class selector specificity beats element selector → .note { color: green; }
Q5
p { color: black } → Missing semicolon after the declaration value
Q6
.box { color: red !importent; } → !important is misspelled — the browser ignores the keyword
Section C: Definitions
Q1
specificity — A score that determines which CSS rule wins when multiple rules target the same element; higher score beats lower
Section D: Fill in the Blanks
Q1
p { color: red; }
Q2
#nav { color: blue; }
Q3
.intro { color: green; }
Q4
h1, p { font-size: 16px; }
Q5
body { color: black !important; }
Section E: Spot the Error
Q1
A — The '.box' rule is missing a semicolon after 'green' — it should be 'color: green;'.
Q2
B — 'colour' is not a valid CSS property — the correct spelling is 'color'.
Q3
C — The colon is missing after 'font-size' in the '#hero' rule — it should be 'font-size: 32px;'.
Q4
D — '!importnt' is a typo — the correct keyword is '!important'.
Q5
E — The 'span' rule is missing its opening curly brace — it should be 'span { color: gray; }'.