Questions
5 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?
05 / 50

What does the :hover pseudo-class do?

Understanding the :hover Pseudo-Class

The :hover pseudo-class in CSS applies styles to an element when the user hovers their pointer (usually a mouse) over it. It is commonly used to create interactive effects, like changing colors, underlines, or other visual cues on buttons, links, and interactive elements.

Example: Using :hover

In this example, the button changes its background and text color when hovered, and the link shows an underline and changes color on hover.

Best Practices
  1. 1

    Use :hover to give visual feedback to users, indicating interactivity.

  2. 2

    Ensure hover effects are not the only way to convey critical information, as touch devices may not have hover capability.

  3. 3

    Combine :hover with transitions for smooth visual effects (e.g., transition: background-color 0.3s;).

  4. 4

    Test hover styles across devices and browsers to ensure consistency.

Difficulty: 2/10
Topics: pseudo-classes, user interaction, accessibility

Scenario Questions

0-2 years experience
  1. 1

    How would you make a button change its background color when a user hovers over it?

  2. 2

    What happens if you apply :hover to a <div> that contains interactive elements like links or inputs?

  3. 3

    If you forget to add a :hover rule for a navigation link, what will the user see when they move the mouse over it?

2-5 years experience
  1. 1

    We have a navigation menu where some items are disabled, but the :hover style still shows a pointer cursor. How would you adjust the CSS so disabled items don’t show hover effects?

  2. 2

    During QA a :hover rule on a dropdown menu stops working on mobile Safari. What could be causing that and how would you fix it?

  3. 3

    You added a :hover rule to a component that uses CSS modules, but the style isn’t applied. Walk me through your debugging steps.

5-8 years experience
  1. 1

    Our design system uses CSS‑in‑JS and we need to support :hover for theming across thousands of components while keeping bundle size low. What trade‑offs would you consider and how would you implement it?

  2. 2

    A large e‑commerce site experiences a flash of unstyled content when :hover styles are loaded after the page renders. How would you restructure CSS delivery to avoid this?

  3. 3

    When building a custom UI library, you need to ensure :hover interactions are accessible for keyboard users and screen readers. How would you design the component to meet those requirements?

8+ years experience
  1. 1

    We are migrating a legacy monolithic stylesheet to a modular design system that must support theming, dark mode, and dynamic :hover states across multiple teams. What architectural approach would you propose to manage :hover definitions while avoiding specificity wars?

  2. 2

    Your organization wants to deprecate pure CSS :hover in favor of a JavaScript‑driven interaction model for better analytics. How would you plan the rollout to minimize risk and maintain backward compatibility?

Follow-up Questions

  • Can you describe a situation where relying solely on :hover caused an accessibility issue?
  • How would you test :hover behavior across different browsers and devices?
  • What are the performance considerations when you have many :hover rules in a large stylesheet?