Learning intentions
- Know what a CSS pseudo-class is and why it is used
- Know and use the four link pseudo-classes:
a:link,a:visited,a:hover,a:active - Know how to style a
<nav>bar by removing bullet points, underlines, and adding hover effects - Understand why changing background colour on hover improves usability
Success criteria
- I can explain what a pseudo-class is in CSS
- I can write
a:hoveranda:visitedrules to style links in different states - I can write CSS to remove underlines from links and bullet points from a nav list
- I can explain why a hover colour change improves the usability of a navigation bar
Answer before the lesson begins.
1. Which CSS pseudo-class applies when the mouse pointer is over an element?
2. Which CSS property removes bullet points from a list?
3. Which CSS property removes the default underline from a link?
Key vocabulary
a:hover.a:hovera:visiteda:activea:link<nav> element, allowing users to move between pages. Typically created by styling an unordered list of anchor elements.text-decorationtext-decoration: none to remove the browser's default underline from links.list-style-typelist-style-type: none removes the bullets entirely, which is essential when using a <ul> for navigation.CSS: Navigation and Pseudo-classes
What is a pseudo-class?
A pseudo-class is a special type of CSS selector that targets an element based on its current state β not just what it is, but what is happening to it right now. The colon (:) separates the element selector from the pseudo-class name:
a:hover { /* applies when mouse is over the link */ } a:visited { /* applies to links the user has already clicked */ }
Pseudo-classes let you style elements differently depending on how users are interacting with them β making interfaces more responsive and easier to use.
The four link pseudo-classes
Links (<a> elements) have four state pseudo-classes. These are often referred to as LVHA β the recommended order to write them in, to avoid conflicts:
| Pseudo-class | When it applies | Browser default |
|---|---|---|
a:link | Unvisited link β user has not clicked it yet | Blue, underlined |
a:visited | Visited link β user has clicked it before | Purple, underlined |
a:hover | User's mouse is currently over the link | No change (stays same as :link) |
a:active | Link is being clicked (mouse button held down) | Red |
Browsers add their own default styles to links. In most cases, web designers override these completely using CSS to match their site's design.
The four pseudo-class states of a link β define them in LVHA order to avoid specificity conflicts
Default browser nav (before CSS)
Without any CSS, a <nav> with a <ul> looks like this:
The links are blue, underlined, and close together β not ideal for navigation.
Styled nav bar (after CSS)
With CSS, the same links can look like this β clean, dark text on a dark background with a highlight on hover:
The CSS that achieves the styled version:
/* Style the nav container */ nav { background-color: #042C53; padding: 0.5rem; } /* Remove bullets if using ul/li for nav links */ nav ul { list-style-type: none; padding: 0; margin: 0; display: flex; } /* Style the links */ nav a { color: #ffffff; text-decoration: none; padding: 0.4rem 0.9rem; border-radius: 4px; } /* Hover state β visual feedback */ nav a:hover { background-color: #185FA5; }
Styling all four link states
You can write separate rules for each link state. Remember the LVHA order β if you write :hover before :link, the hover effect may not work due to specificity:
a:link { color: #185FA5; } /* unvisited β blue */ a:visited { color: #9090b0; } /* visited β grey */ a:hover { color: #042C53; background-color: #E6F1FB; } /* hover */ a:active { color: #1D9E75; } /* being clicked */
Why hover effects improve usability
A usability principle states that interactive elements should give feedback when they are interacted with. When a user moves their mouse over a navigation link, a background colour change:
- Makes it clear the element is clickable (users know it is interactive)
- Helps users track which link they are about to click
- Reduces the chance of clicking the wrong link
Without any hover effect, all links look the same before and during hovering, which reduces clarity and usability.
Worked examples
Compare unstyled nav links with styled nav links. The HTML structure is the same β only the CSS differs.
HTML (same in both cases):
<nav> <ul> <li><a href="index.html">Home</a></li> <li><a href="gallery.html">Gallery</a></li> <li><a href="contact.html">Contact</a></li> </ul> </nav>
Without CSS: Blue underlined links with bullet points.
With CSS (styled version):
nav { background-color: #042C53; padding: 0.6rem 1rem; } nav ul { list-style-type: none; padding: 0; display: flex; gap: 0.25rem; } nav a { color: #fff; text-decoration: none; padding: 0.4rem 0.9rem; border-radius: 4px; } nav a:hover { background-color: #185FA5; }
Write CSS to style links in all four states: unvisited = #185FA5 (blue); hover = #042C53 text on #E6F1FB background; visited = #9090b0 (grey); active = #1D9E75 (green).
text-decoration: none on the base a rule.a { text-decoration: none; } a:link { color: #185FA5; } a:visited { color: #9090b0; } a:hover { color: #042C53; background-color: #E6F1FB; } a:active { color: #1D9E75; }
Write CSS to style a <nav> containing a <ul> of links. Remove bullet points, remove underlines, display items horizontally, and add a hover background.
nav ul to remove bullets and default list padding.nav a to remove underlines and set the link colour.nav a:hover to change the background colour when hovering β giving users clear feedback.nav ul { list-style-type: none; padding: 0; margin: 0; } nav a { text-decoration: none; color: #042C53; padding: 0.5rem 1rem; display: block; } nav a:hover { background-color: #E6F1FB; }
An existing page has a <nav> with a <ul> of three links. The links currently appear as a bulleted list of blue underlined text. Write CSS rules to:
- Remove the bullet points from the
nav ul - Make the
nav alinks appear dark blue (#042C53) with no underline - Add a light blue background (
#E6F1FB) onnav a:hover
nav ul { list-style-type: none; padding: 0; } nav a { color: #042C53; text-decoration: none; } nav a:hover { background-color: #E6F1FB; }
hover before link or visited (ignoring LVHA order). If you write a:hover before a:visited, the visited state may override hover because it comes later and has the same specificity. Always write link states in LVHA order: link, visited, hover, active.list-style-type: none to the <li> instead of the <ul>. The list-style-type property is set on the list container (ul or ol), not on individual list items. nav ul { list-style-type: none; } removes all bullets from that list.text-decoration: none with list-style-type: none. text-decoration: none removes underlines from text (links). list-style-type: none removes bullet points from lists. They do very different things β both are needed for a clean nav bar.a:hover can change the background colour as well as text colour. A hover effect that only changes text colour is less visible. Changing the background-color creates a clear, unmissable highlight that significantly improves usability.Pseudo-class questions at N5 often appear in two ways: (1) "Write CSS to style links so they change colour when hovered" β expect to write an a:hover rule with at least one property. (2) "Describe the effect of this CSS code" β read the pseudo-class and describe what triggers it.
For usability questions: "explain why changing background colour on hover is good for usability" β a strong 2-mark answer is: "It shows users that the link is interactive (1 mark) and makes it clear which link they are about to click, reducing the risk of clicking the wrong one (1 mark)."
Remember LVHA β it appears in exams as "put these link pseudo-classes in the correct order". The answer is always: link, visited, hover, active.
Questions 1β3 are auto-checked. Questions 4β8 are self-marked β write your answer, then reveal the model answer to check your work.
1. Which pseudo-class applies when a user's mouse is over a link? TYPE 1
2. What does list-style-type: none do? TYPE 1
3. Which CSS property removes the underline from links? TYPE 1
4. A link has these three CSS rules. Predict its appearance: (a) before hovering; (b) when hovering; (c) after being clicked (visited). (3 marks) TYPE 2
a:link { color: #185FA5; } a:hover { color: #ffffff; background-color: #042C53; } a:visited { color: #9090b0; }
(b) When hovering (a:hover): The link text turns white (#ffffff) and the background becomes dark navy (#042C53). This creates a strong highlight effect.
(c) After being clicked (a:visited): The link text turns grey (#9090b0) to indicate it has been visited.
1 mark per state correctly described (must match the CSS colour values).
5. Write CSS to style a navigation bar: remove underlines from nav links; change their colour to #185FA5; add a background-color of #E6F1FB on hover; remove bullet points from the nav ul. (3 marks) TYPE 2
nav ul {
list-style-type: none;
padding: 0;
}
nav a {
text-decoration: none;
color: #185FA5;
}
nav a:hover {
background-color: #E6F1FB;
}
Marks: nav ul with list-style-type: none (1), nav a with text-decoration: none and correct colour (1), nav a:hover with correct background-color (1).
6. Explain why changing the background colour of a navigation link on hover is considered good for usability. (2 marks) TYPE 2
2. It makes it immediately clear which link the user is about to click, reducing the chance of clicking the wrong link β especially important on mobile-like layouts where links are close together (1 mark).
Accept any two distinct usability points. Strong answers reference: interactivity feedback, clarity of selection, reduced error rate.
7. Write a:hover and a:visited rules to give this appearance: visited links show in grey (#9090b0) with no underline; hovering turns the background to #E1F5EE and the text to #085041. (2 marks) TYPE 2
a:visited {
color: #9090b0;
text-decoration: none;
}
a:hover {
background-color: #E1F5EE;
color: #085041;
}
1 mark per rule (correct pseudo-class selector + correct properties and values).
8. A pupil writes a { text-decoration: none; } for a nav bar but the underlines still appear on the links. Suggest one reason why this might not be working. (1 mark) TYPE 2
1. The CSS rule may be overridden by a higher-specificity rule elsewhere in the stylesheet (e.g. a class selector or inline style targeting the same links).
2. The CSS file may not be linked correctly to the HTML page, so none of the stylesheet rules are being applied.
3. There may be a typo in the CSS property name β e.g.
text-deceration instead of text-decoration β causing the browser to ignore the rule.4. The CSS rule is written in an
a:link or a:visited rule with a different value that overrides the base a rule (due to LVHA specificity issues).1 mark for any valid, well-reasoned suggestion.
Suggested timing: Single 1-hour period. Lighter content than WDD8. Spend 15 minutes on the concept of pseudo-classes and LVHA order (open a real website and hover over nav links on the projector first β see the effect before explaining it). 10 minutes on now-you-try. 35 minutes on task set Q1βQ6 in class. Q7βQ8 as extension.
Opening demo: Before any CSS explanation, open a well-known website (BBC, SQA, etc.) on the projector. Hover slowly over the navigation links. Watch the highlight effect appear. Ask pupils: "What changed? Why does it do that?" This motivates the lesson better than a definition.
LVHA order: Write the mnemonic on the board β "Love Visits High Altitude" or simply "LVHA". The order matters because same-specificity rules follow the cascade (later wins), so :hover must come after :link and :visited to override them correctly.
Q4 (predict appearance) is an excellent exam-practice question. Pupils must read code and visualise the result β exactly what the SQA asks in the question paper.