HTML | readonly Attribute
It is a Boolean attribute which is used to specify that the text written in input or text area Element is read-only. It means that a user can not modify or changes a content already present in a particular Element (However, a user can tab to it, highlight it, and copy the text from it). Whereas a JavaScript can be used to change the read-only value and make the input field editable.
Elements: This attribute is used with two elements which are listed below:
- <input>: It is used to readonly attribute to read the content only.
- <text-area> It is used to hold the readonly attribute.
Example: 1
<input readonly>
<!DOCTYPE html> <html> <head> <title>readonly attribute</title> <style> body { text-align: center } h1, h2 { color: green; font-style: italic; } </style> </head> <body> <h1>GeeksForGeeks</h1> <h2>readonly attribute in Input Element</h2> <form action=""> Email: <input type="text" name="email"> <br> Country: <input type="text" name="country" value="Noida" readonly> <br> <input type="submit" value="Submit"> </form> </body> </html> |

Wxample:2
<textarea readonly>
<!DOCTYPE html> <html> <head> <title>readonly attribute</title> <style> body { text-align: center; } h1, h2 { color: green; font-style: italic; } </style> </head> <body> <h1>GeeksForGeeks</h1> <h2>readonly attribute in input Element</h2> <textarea rows="4" cols="40" readonly> GeeksForGeeks is a good website for learning computer science. It is a computer science portal for geeks. </textarea> </body> </html> |

Supported Browsers: The browser supported by readonly attribute are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
Recommended Posts:
- HTML | input readonly Attribute
- HTML | <textarea> readonly Attribute
- How to use input readonly attribute in jQuery ?
- How to add readonly attribute to an input tag in JavaScript ?
- HTML | DOM Input URL readOnly Property
- HTML | DOM Textarea readOnly Property
- HTML | DOM Input Time readOnly Property
- HTML | DOM Input Month readOnly Property
- HTML | DOM Input Week readOnly Property
- HTML | DOM Input Email readOnly Property
- HTML | DOM Input Number readOnly Property
- HTML | DOM Input Date readOnly Property
- HTML | DOM Input DatetimeLocal readOnly Property
- HTML | DOM Input Datetime readOnly Property
- HTML | DOM Input Password readOnly 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.



