
CSS Topics
- CSS Intro
- CSS How To
- CSS Editors
- CSS Properties
- CSS Selectors
- .class
- .class1.class2
- .class1 .class2
- #id
- * (all)
- element
- element.class
- element,element
- element element
- element>element
- element+element
- element1~element2
- [attribute]
- [attribute=value]
- [attribute~=value]
- [attribute|=value]
- [attribute^=value]
- [attribute$=value]
- [attribute*=value]
- :active
- ::after
- ::before
- :checked
- :default
- :disabled
- :empty
- :enabled
- :first-child
- ::first-letter
- ::first-line
- :first-of-type
- :focus
- :fullscreen
- :has()
- :hover
- :in-range
- :indeterminate
- :invalid
- :lang()
- :last-child
- :last-of-type
- :link
- ::marker
- :not()
- :nth-child()
- :nth-last-child()
- :nth-last-of-type()
- :nth-of-type()
- :only-of-type
- :only-child
- :optional
- :out-of-range
- ::placeholder
- :read-only
- :read-write
- :required
- :root
- ::selection
- :target
- :valid
- :visited
- CSS Comments
- CSS Length
- CSS Image Sprites
- CSS Grid Layout
- CSS Grid Flexbox
- CSS @charset Rule
- CSS @font-face Rule
- CSS @import Rule
- CSS @keyframes Rule
- CSS @media Rule
CSS :read-write Selector

Photo Credit to CodeToFun
Introduction
The :read-write
selector in CSS is used to select elements that are editable by the user.
This pseudo-class is typically applied to form elements such as text inputs, <textarea>
, and other content-editable elements where the user can enter or modify the data. It helps in providing visual feedback or different styling for fields that can be written to.
Syntax
The signature of the :read-write
Selector is as follows:
:read-write {
/* CSS properties */
}
The :read-write
pseudo-class is typically used for elements that are editable and can accept input, like text fields, but it excludes elements that are marked as readonly
or disabled
.
Example
Here is an example of how to use the :read-write
selector in CSS:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS :read-write Selector Example</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<form>
<input type="text" id="username" placeholder="Enter your username">
<textarea id="bio" placeholder="Write about yourself"></textarea>
<input type="text" id="readonly" value="This is read-only" readonly>
<input type="submit" value="Submit">
</form>
</body>
</html>
CSS
/* Style for read-write elements */
:read-write {
background-color: #f0f8ff;
border: 2px solid blue;
}
/* Style for read-only elements */
:read-only {
background-color: #f5f5f5;
border: 2px solid gray;
}
In this example:
- Editable form fields like the username input and textarea have a blue border and a light background.
- The read-only field has a gray border and a light gray background, indicating it's not editable.
Usage Tips
- The
:read-write
pseudo-class only targets elements that are editable and writable by the user. This includes form fields that are notreadonly
ordisabled
. - You can combine the
:read-write
pseudo-class with other form-specific pseudo-classes like:focus
for enhanced styling on focused, writable elements.
Common Pitfalls
- Be aware that
:read-write
applies to editable fields, but if an element has thereadonly
ordisabled
attribute, it will not be affected by this pseudo-class. Use :read-only for non-editable fields. :read-write
may behave differently in certain form elements, such as select dropdowns, so be sure to test in different browsers and environments for consistent behavior.
Conclusion
The :read-write
selector is a handy pseudo-class for styling editable fields, allowing developers to visually distinguish between elements that users can interact with and those they cannot. By applying this pseudo-class, you can enhance user experience and provide clear visual cues for writable content.
Join our Community:
Author

For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.
Buy me a coffee to make codetofun.com free for everyone.
Buy me a Coffee
If you have any doubts regarding this article (CSS :read-write Selector), please comment here. I will help you immediately.