CSS :read-write
Pseudo-Class
The :read-write
pseudo-class selects input fields or elements that are editable by the user. It helps apply styles specifically to editable form fields while ignoring readonly
elements.
1. Syntax
✅ This applies a light blue background to editable input fields.
2. Example – Highlight Editable Inputs
✅ Editable inputs have a green border and light green background.
✅ Read-only fields have a gray border and light gray background.
3. Styling contenteditable
Elements
The :read-write
pseudo-class also applies to elements with contenteditable="true"
.
✅ Editable <div>
elements get a dashed blue outline.
4. :read-write
vs :read-only
Pseudo-Class | Targets |
---|---|
:read-write | Editable fields (input , textarea , contenteditable ) |
:read-only | Fields with the readonly attribute |
✅ Helps differentiate editable vs. non-editable fields.
5. Browser Support
✅ Supported in all modern browsers (Chrome, Firefox, Edge, Safari).
❌ Not supported in Internet Explorer.
6. Best Practices
✔ Use :read-write
to highlight interactive fields.
✔ Combine with :read-only
for better form usability.
✔ Works great for content-editable elements.