Questions
7 of 50
1What is a pseudo-class in CSS?
2How are pseudo-classes different from pseudo-elements?
3What is the syntax of a pseudo-class in CSS?
4Give some commonly used pseudo-classes.
5What does the :hover pseudo-class do?
6What’s the purpose of the :active pseudo-class?
7How does the :visited pseudo-class work for links?
8What is the :focus pseudo-class used for?
9What does the :checked pseudo-class do?
10How does the :disabled pseudo-class behave?
11What is the difference between :first-child and :first-of-type?
12How do :nth-child() and :nth-of-type() differ?
13How do you select every odd or even element using pseudo-classes?
14How can you style an element when it’s being hovered over along with its child?
15What does the :not() pseudo-class do?
16How can you use multiple pseudo-classes together?
17What is the difference between :link and :visited?
18What does the :target pseudo-class represent?
19How can you use :empty to detect empty elements?
20How does the :root pseudo-class differ from the html selector?
21What does the :valid and :invalid pseudo-class do?
22How can you use :required and :optional pseudo-classes in forms?
23What is the use of :in-range and :out-of-range?
24What does :read-only and :read-write do?
25How can you style an input field when it’s autofilled?
26How does the :focus-within pseudo-class work?
27What’s the difference between :focus and :focus-visible?
28What is the purpose of the :placeholder-shown pseudo-class?
29How can you style a checkbox when it is checked or unchecked?
30How can you style invalid form inputs without JavaScript?
31Can pseudo-classes be chained together? Give an example.
32What is the specificity of pseudo-classes compared to normal selectors?
33How can you use :not() effectively to exclude elements from styling?
34How does :has() pseudo-class work, and why is it powerful?
35Is :has() supported in all browsers?
36How does :is() differ from :where() in terms of specificity?
37How can you combine :is() or :where() with other selectors for cleaner code?
38What’s the difference between :nth-child() and :nth-last-child()?
39How can you style only the last element of a list using pseudo-classes?
40What does the :lang() pseudo-class do?
41How do you change a button’s color when hovered but not when disabled?
42How can you highlight the current section in a menu using :target?
43How can you style a form field differently when focused and valid?
44How do you style every third list item differently?
45How can you style alternate table rows without adding extra classes?
46How do you hide empty <p> tags using pseudo-classes?
47How can you style the parent when any child inside it is focused?
48How can you highlight a link only when it’s both focused and hovered?
49How can you style the first letter of only the first paragraph using pseudo-classes?
50How would you use :has() to select a <div> that contains an image?
07 / 50

How does the :visited pseudo-class work for links?

Understanding the :visited Pseudo-Class

The :visited pseudo-class in CSS applies styles to links (<a> elements) that the user has previously visited. This allows designers to visually differentiate between links that have been clicked and those that haven't.

Example: Using :visited

In this example, links that the user has not visited appear blue, while visited links appear purple.

Best Practices and Limitations
  1. 1

    Use :visited to provide visual cues about link history, improving navigation experience.

  2. 2

    Browsers restrict which CSS properties can be applied to :visited for privacy reasons (e.g., color changes are allowed, but background images are typically blocked).

  3. 3

    Combine :visited with :hover and :active for consistent interactive feedback.

  4. 4

    Test link styling across browsers, as some may handle visited links differently to prevent history leakage.

Difficulty: 5/10
Topics: CSS selectors, privacy restrictions, browser rendering

Scenario Questions

0-2 years experience
  1. 1

    You need to style links that the user has already visited to appear purple. How would you write the CSS selector, and what are the limitations you need to be aware of?

  2. 2

    If a user’s browser is set to block history sniffing, what will happen to the colors you apply with :visited?

2-5 years experience
  1. 1

    We have a component that conditionally adds a class to links based on whether they’re internal or external. After deploying, the visited styling stopped working on some pages. Walk me through how you would debug this.

  2. 2

    Explain why changing the background-image of a :visited link is ignored by browsers, and how you would achieve a visual indication of visited state without violating privacy restrictions.

5-8 years experience
  1. 1

    Our site uses a CSS-in-JS library that generates class names at runtime. How would you ensure that :visited styles are applied consistently across server‑rendered and client‑only components, considering browser privacy rules?

  2. 2

    Discuss the performance and security trade‑offs of using :visited to indicate read status in a large news platform with millions of users, and propose an alternative approach if needed.

8+ years experience
  1. 1

    We are migrating a legacy monolith to a micro‑frontend architecture. Different teams own different style systems, and some still rely on :visited for user‑read tracking. How would you standardize link styling while avoiding cross‑team privacy regressions?

  2. 2

    Consider a scenario where a third‑party widget injects its own stylesheet that overrides your :visited rules. What governance or tooling would you put in place to prevent unintended side effects at scale?

Follow-up Questions

  • Which CSS properties are allowed on :visited and why?
  • How would you verify that your :visited styling works across major browsers?
  • What security or privacy concerns arise from exposing visited state?