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

How does the :disabled pseudo-class behave?

Understanding the :disabled Pseudo-Class

The :disabled pseudo-class in CSS targets form elements that are currently disabled. Disabled elements cannot be interacted with by the user, such as <input>, <button>, <select>, and <textarea>. This pseudo-class allows you to style these elements differently to indicate their inactive state.

Example: Using :disabled

In this example, disabled inputs and buttons are visually distinct and indicate that they cannot be interacted with, improving user experience and accessibility.

Best Practices
  1. 1

    Use :disabled to style elements clearly when they cannot be interacted with.

  2. 2

    Combine with visual cues like color, opacity, and cursor changes for better UX.

  3. 3

    Do not rely solely on color to indicate disabled state; ensure sufficient contrast and other cues for accessibility.

  4. 4

    Test disabled styles across browsers, as form element styling can vary.

Difficulty: 4/10
Topics: pseudo-classes, form controls, accessibility

Scenario Questions

0-2 years experience
  1. 1

    If you add button:disabled { opacity: 0.5; } to a page, what will happen when the button element has the disabled attribute? Explain why.

  2. 2

    You need to style a <select> element differently when it's not interactive. How would you use the :disabled pseudo‑class to achieve that?

  3. 3

    What happens if you apply pointer-events: none to a disabled input—does the :disabled selector still match?

2-5 years experience
  1. 1

    We have a form where some inputs are dynamically disabled via JavaScript. The styles for input:disabled aren't applying. What could be causing that and how would you fix it?

  2. 2

    During a UI review, a disabled button still receives focus and can be activated via keyboard. Why might the :disabled pseudo‑class not be preventing interaction, and what changes would you make?

  3. 3

    Explain the difference between using the disabled attribute versus adding a .disabled class and styling with .disabled. When would each be appropriate?

5-8 years experience
  1. 1

    Our component library needs to support custom form controls that mimic native disabled behavior across browsers. How would you design the CSS and JavaScript to ensure :disabled styles work consistently, considering shadow DOM and accessibility?

  2. 2

    We discovered that in Safari, :disabled does not apply to <fieldset> children when the fieldset is disabled. How would you handle this edge case in a large‑scale UI framework?

  3. 3

    Discuss performance implications of using :disabled selectors on a page with thousands of form elements. How would you mitigate any impact?

8+ years experience
  1. 1

    We're planning a migration from a legacy UI that uses .disabled classes to a standards‑compliant approach using the native disabled attribute and :disabled pseudo‑class. What architectural considerations, testing strategies, and rollout plan would you propose?

  2. 2

    In a multi‑team product, some teams need brand‑specific disabled styling while others rely on default :disabled behavior for accessibility. How would you design a theming system that balances these needs without breaking accessibility?

  3. 3

    Consider a design system that must support both web and native mobile (React Native) where the concept of :disabled doesn't exist. How would you abstract disabled‑state handling across platforms to keep a consistent developer experience?

Follow-up Questions

  • How does the browser decide whether an element matches :disabled?
  • What accessibility concerns arise if a disabled element is still focusable?
  • Can you describe how cascade order affects multiple :disabled rules?