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

Is :has() supported in all browsers?

Browser Support for the :has() Pseudo-Class

The :has() pseudo-class is powerful but its browser support varies. Modern browsers have started supporting it, but older browsers and some versions may not recognize it yet.

Current Browser Support
  1. 1

    Fully supported in the latest versions of Chrome, Edge, Safari, and Opera.

  2. 2

    Firefox started supporting it experimentally in newer versions, but it may require enabling a flag or be limited in some releases.

  3. 3

    Internet Explorer and very old browser versions do not support :has().

  4. 4

    Always test critical use cases and provide fallbacks or progressive enhancement for unsupported browsers.

Because :has() can affect styling dynamically based on child elements, you may want to use feature queries (@supports) or fallback styles to ensure a good user experience in browsers that do not support it.

Example: Using @supports for Fallback
Best Practices
  1. 1

    Check browser compatibility before using :has() in production projects.

  2. 2

    Use feature queries (@supports) to apply styles only when supported.

  3. 3

    Consider progressive enhancement so that the UI works even without :has().

  4. 4

    Test on multiple browsers to ensure consistent appearance and functionality.

Difficulty: 6/10
Topics: CSS selector support, browser compatibility, feature detection

Scenario Questions

0-2 years experience
  1. 1

    You're building a card component that highlights parent containers when a button inside is hovered — you used :has() but it doesn't work in Chrome. What do you check first?

  2. 2

    Your teammate says :has() works fine in their browser, but your design breaks. What’s the most likely reason, and how would you verify it?

2-5 years experience
  1. 1

    A user reports that the 'selected' state on a navigation menu isn't showing up on their iPhone — you used :has() to style the parent based on child state. How do you debug this?

  2. 2

    You're implementing a dynamic form validation UI using :has() to style parent fields when inputs are invalid. QA finds it doesn't work on Android Chrome 90. What’s your plan to fix it without rewriting the entire component?

5-8 years experience
  1. 1

    You’re designing a reusable component library that uses :has() for advanced parent-child styling. How do you balance modern CSS elegance with supporting legacy enterprise clients on outdated browsers?

  2. 2

    Your team wants to adopt :has() to reduce JavaScript-driven DOM manipulation for hover states. What performance, maintenance, and compatibility tradeoffs would you evaluate before committing?

8+ years experience
  1. 1

    Your company’s flagship product still supports IE11 and iOS 13, but engineering wants to migrate to :has() for cleaner CSS. How do you structure a phased migration plan that minimizes user impact and technical debt?

  2. 2

    You’re leading a cross-team initiative to standardize CSS architecture. How do you advocate for or against adopting :has() given its inconsistent browser support, and what metrics would you use to justify the decision?

Follow-up Questions

  • How would you detect if :has() is supported at runtime?
  • What fallback would you implement for older browsers when using :has() for visual state indicators?
  • Have you ever shipped a feature that broke because of missing :has() support?