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

Can pseudo-classes be chained together? Give an example.

Chaining Pseudo-Classes in CSS

Yes, pseudo-classes can be chained together in CSS. Chaining allows you to apply styles only when an element satisfies multiple conditions simultaneously, making your styling more precise and powerful.

Key Points About Chaining Pseudo-Classes
  1. 1

    Pseudo-classes are chained by writing them one after another without spaces (e.g., a:hover:active).

  2. 2

    You can mix structural and dynamic pseudo-classes (e.g., li:first-child:hover).

  3. 3

    Chaining can also be combined with :not() for exclusions (e.g., input:required:not(:focus)).

Example: Chaining Pseudo-Classes

In this example, only the first list item changes color when hovered. Checked checkboxes change color on hover, and enabled buttons change background on hover. Chaining pseudo-classes ensures styles apply only under the combined conditions.

Best Practices
  1. 1

    Chain pseudo-classes logically to target elements accurately without extra HTML classes.

  2. 2

    Keep chains readable and avoid over-complicating selectors.

  3. 3

    Test combined pseudo-classes across browsers to ensure consistent behavior.

  4. 4

    Use transitions for smooth dynamic changes and better UX.

Difficulty: 3/10
Topics: pseudo-class chaining, CSS specificity, selector combinators

Scenario Questions

0-2 years experience
  1. 1

    You're trying to style a button that's both focused and hovered, but the styles aren't applying. How would you write the CSS selector and what common mistake might you be making?

  2. 2

    A link turns red on hover, but when you click it, the color doesn't change. How would you fix it using pseudo-class chaining?

  3. 3

    What happens if you write .btn:disabled:hover instead of .btn:hover:disabled? Does the order matter and why?

2-5 years experience
  1. 1

    Our dropdown menu’s :hover styles break when users tab through it on mobile. The :focus state overrides the hover styles, but we want both to work. How would you debug and fix this without breaking accessibility?

  2. 2

    A component works fine in Chrome but not in Safari when chaining :nth-child(odd):focus. What could be going wrong, and how would you investigate?

  3. 3

    We have a form with required fields that show an error state on :invalid. But when users tab into them, the :focus style hides the error indicator. How would you structure the CSS to show both states clearly?

5-8 years experience
  1. 1

    We’re building a reusable button component that needs to support :hover, :focus, :active, and :disabled states simultaneously, but the CSS bundle is bloated due to combinatorial explosion. How would you architect the styling system to avoid redundancy while preserving state combinations?

  2. 2

    In a large legacy app, chaining pseudo-classes like :not(.is-disabled):hover is causing performance issues on low-end devices. How would you profile and optimize this without losing functionality?

  3. 3

    A design system uses :focus-visible to improve accessibility, but some components break when combined with :active. How would you design a test strategy to catch these edge cases across browsers and devices?

8+ years experience
  1. 1

    We’re migrating from a legacy CSS framework that uses JavaScript to simulate pseudo-class states to native CSS chaining. How would you design a phased rollout plan to avoid visual regressions across 50+ components and 3 different user personas?

  2. 2

    Our design system supports 8+ state combinations per component (e.g., :hover:focus:disabled:valid). How do you balance expressiveness with bundle size, maintainability, and developer onboarding in a global team?

  3. 3

    A cross-team component library uses pseudo-class chaining inconsistently — some teams use :focus:hover, others use :hover:focus. How would you enforce a standardized pattern across 20+ product teams without breaking existing UIs?

Follow-up Questions

  • What happens if you chain two mutually exclusive pseudo-classes like :hover:active on a button?
  • How does chaining affect CSS specificity compared to using a class and a pseudo-class together?
  • Can you chain pseudo-classes with pseudo-elements? Why or why not?