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

What does :read-only and :read-write do?

Understanding the :read-only and :read-write Pseudo-Classes in CSS

The :read-only and :read-write pseudo-classes in CSS allow you to style form elements based on their editability state. They help indicate to users whether an input can be modified or is read-only.

How They Work
  1. 1

    :read-only – Selects form elements that are not editable (e.g., elements with the readonly attribute).

  2. 2

    :read-write – Selects form elements that are editable and can be changed by the user.

  3. 3

    These pseudo-classes dynamically reflect the current state of the element.

Example: Using :read-only and :read-write

In this example, the editable input has a white background with a solid border, while the read-only input has a gray background and dashed border, clearly indicating which fields can be modified.

Best Practices
  1. 1

    Use :read-only and :read-write to provide visual feedback about editable states of form elements.

  2. 2

    Combine with :focus or :hover to enhance interactivity and UX.

  3. 3

    Ensure visual cues are accessible and distinguishable, not relying solely on color.

  4. 4

    Test behavior across different browsers and input types to ensure consistent styling.

Difficulty: 3/10
Topics: CSS pseudo-classes, form element states, user interaction styling

Scenario Questions

0-2 years experience
  1. 1

    You're building a form where some fields should appear grayed out but still selectable — how would you style them using :read-only vs. :read-write?

  2. 2

    A teammate says their input isn't styling correctly with :read-only — what are two common reasons this might happen?

  3. 3

    If you set an input to readonly in HTML, but your CSS rule using :read-write is still applying, what’s likely wrong?

2-5 years experience
  1. 1

    Our dynamic form toggles fields between editable and read-only based on user role — sometimes the styling breaks after state changes. How would you debug this using :read-only and :read-write?

  2. 2

    We’re using a third-party form library that doesn’t set readonly attributes consistently. How would you ensure visual consistency for read-only states without modifying the library?

  3. 3

    A user reports that a read-only field still looks clickable. How would you use :read-only and :read-write to fix the UX without touching JavaScript?

5-8 years experience
  1. 1

    We have a legacy form system with hundreds of dynamically generated inputs — some use readonly, others use disabled or JS-controlled classes. How would you refactor the styling layer to unify read-only behavior using CSS pseudo-classes while minimizing regressions?

  2. 2

    In a high-performance dashboard with 500+ read-only fields, we’re seeing layout thrashing. How might :read-write and :read-only impact rendering performance, and how would you optimize it?

  3. 3

    Our design system uses custom components that simulate read-only state via CSS classes. What are the accessibility and maintainability tradeoffs of switching to native readonly attribute + :read-only pseudo-class?

8+ years experience
  1. 1

    We’re migrating from a proprietary form framework to a standards-based one — many legacy components rely on JS-managed classes for read-only states. How would you design a phased migration strategy that preserves UX while adopting :read-only and :read-write without breaking existing workflows across 10+ teams?

  2. 2

    Our global product supports 20+ languages and complex form layouts. Some locales treat read-only fields as non-interactive, others as selectable. How would you architect a CSS strategy using :read-only and :read-write that accommodates cultural UX expectations without duplicating styles?

  3. 3

    A compliance audit flagged our forms for inconsistent read-only state representation. How would you enforce consistent use of :read-only and :read-write across 50+ micro-frontends, and what tooling or governance would you put in place to prevent drift?

Follow-up Questions

  • How would you style a read-only input differently from a disabled one?
  • What happens if you apply :read-write to a <div> with contenteditable?
  • Why might a developer prefer :read-only over adding a custom class like .readonly?