Pseudo-classes

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

Pseudo-classes

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which syntax correctly applies a pseudo-class?
A a:hover { color: red; }
B a.hover { color: red; }
2. :hover activates when...
A the mouse pointer is over the element
B the element receives keyboard focus
3. Which pseudo-class targets an element while it is being clicked?
A :active
B :focus
4. li:first-child selects...
A every li element on the page
B the first li inside its parent
5. Pseudo-classes use a single colon or double colon?
A Double colon — e.g. ::hover
B Single colon — e.g. :hover

Match the Pairs

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

Left columnRight column
1a:hover AWrong — a dot selects a class, not a state. Use a colon: a:hover
2input:focus BStyles an input when it receives keyboard or click focus
3Targets the last child element in a parent CWrong — pseudo-classes use one colon, not two. Use button:active
4Targets elements by their numeric position among siblings Dli:last-child
5a.hover { color: red; } Ep:nth-child(2)
6button::active { background: blue; } FStyles a link when the mouse pointer is over it

Definitions

pseudo-class

Fill in the Blanks

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

1.
a:_____ { color: red; }
2.
input:_____ { outline: 2px solid blue; }
3.
li:___________ { font-weight: bold; }
4.
li:__________ { color: gray; }
5.
button:______ { background: green; }

Spot the Error

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

Question 1
A a.hover {
B color: orange;
C }
Question 2
A input:focus {
B border 2px solid blue;
C }
Question 3
A button:active {
B background: darkblue;
C colour: white;
Question 4
A a:visited {
B text-decoration: none;
C color: purple;
D opacity = 0.8;
Question 5
A li:first-child {
B font-size: 18px;
C font-weight: bold;
D color: navy;
E text-align centre;

Answer Key

Pseudo-classes
Section A: Quick Questions
Q1
A — a:hover { color: red; }
Q2
A — the mouse pointer is over the element
Q3
A — :active
Q4
B — the first li inside its parent
Q5
B — Single colon — e.g. :hover
Section B: Match the Pairs
Q1
a:hover → Styles a link when the mouse pointer is over it
Q2
input:focus → Styles an input when it receives keyboard or click focus
Q3
Targets the last child element in a parent → li:last-child
Q4
Targets elements by their numeric position among siblings → p:nth-child(2)
Q5
a.hover { color: red; } → Wrong — a dot selects a class, not a state. Use a colon: a:hover
Q6
button::active { background: blue; } → Wrong — pseudo-classes use one colon, not two. Use button:active
Section C: Definitions
Q1
pseudo-class — A keyword added after a selector with a colon that targets an element based on its state or position, e.g. :hover or :focus.
Section D: Fill in the Blanks
Q1
a:hover { color: red; }
Q2
input:focus { outline: 2px solid blue; }
Q3
li:first-child { font-weight: bold; }
Q4
li:last-child { color: gray; }
Q5
button:active { background: green; }
Section E: Spot the Error
Q1
A — Pseudo-classes use a colon, not a dot. a.hover tries to match an element with class='hover'. The correct selector is a:hover.
Q2
B — CSS declarations need a colon between the property and value. It should be border: 2px solid blue; not border 2px solid blue;
Q3
C — The CSS property is color (American English), not colour. It should be color: white; not colour: white;
Q4
D — CSS uses a colon between property and value, not an equals sign. It should be opacity: 0.8; not opacity = 0.8;
Q5
E — A colon is missing between property and value, and CSS uses the American spelling center. It should be text-align: center;