How to make text input non-editable using CSS?

The read-only attribute in HTML is used to create a text input non-editable. But in case of CSS, the pointer-events property is used to stop the pointer events.

Syntax:

pointer-events: none;

Example 1: This example shows two input text, in which one is non-editable.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html
    <head
        <title
            Disable Text Input field
        </title
          
        <style>
        .inputClass {
            pointer-events: none; 
        }
        </style>
    </head
      
    <body style = "text-align:center;"
  
        <h1 style = "color:green;"
            GeeksForGeeks 
        </h1
          
        Non-editable:<input class="inputClass"
            name="input" value="GeeksForGeeks">
          
        <br><br>
          
        Editable:<input class="inputClass2"
            name="input" value="GeeksForGeeks">
    </body
</html>                    

chevron_right


Output:

Example 2: This example creates two input text, both of them are non-editable.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html>
   <head>
      <title
         Disable Text Input field
      </title>
        
      <style>
         .inputClass {
            pointer-events: none; 
         }
      </style>
   </head>
     
   <body style = "text-align:center;">
         
      <h1 style = "color:green;"
         GeeksForGeeks 
      </h1>
        
      Non-editable:<input class="inputClass"
        name="input" value="GeeksForGeeks">
        
      <br><br>
        
      Non-Editable:<input class="inputClass"
        name="input" value="GeeksForGeeks">
   </body>
</html>

chevron_right


Output:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.