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.
<!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
filter_none
Output:

Example 2: This example creates two input text, both of them are non-editable.
<!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
filter_none
Output:

Recommended Posts:
- How to select all text in HTML text input when clicked using JavaScript?
- HTML | DOM Input Text Object
- JQuery | Set the value of an input text field
- How to get the value of text input field using JavaScript?
- HTML | DOM Input Text value Property
- HTML | <input type="text">
- HTML | DOM Input Text name Property
- HTML | DOM Input Text form Property
- HTML | DOM Input Text maxLength Property
- HTML | DOM Input Text select() Method
- HTML | DOM Input Text required Property
- How to select text input fields using CSS selector ?
- HTML | DOM Input Text defaultValue Property
- HTML | DOM Input Text disabled Property
- HTML | DOM Input Text placeholder Property
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.



