Style elements with a "readonly" attribute with CSS

To select elements that are read-only, use the CSS :read-only selector.


You can try to run the following code to implement the :read-only selector

Live Demo

<!DOCTYPE html>
         input:read-only {
            background-color: blue;
            color: white;
         Subject: <input type = "text" name = "subject" value = "Maths"><br>
         Student: <input type = "text" name = "student" readonly value = "Amit"><br>

Updated on: 01-Jul-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started