Open In App

What is the use of readonly Attribute in HTML ?

Last Updated : 20 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

The “readonly” attribute in HTML is used to specify that an input field or textarea is read-only, meaning that its value cannot be modified by the user. This attribute is commonly used when displaying data that should not be edited but still needs to be visible to the user for reference or interaction purposes.

Syntax

<input type="text" readonly>
<textarea readonly>...</textarea>

Key Point of readonly Attribute

Key Point Description
Read-only Field The “readonly” attribute prevents users from modifying the content of the input field or textarea, but they can still select and copy the text.
Disabled vs. Readonly Unlike the “disabled” attribute, which completely disables an input field, the “readonly” attribute allows the field to remain interactive for the selection and copying of text.

Features

  • Form Submission: Data from read-only fields is included in form submissions, enabling server-side processing
<form action="submit.php">
  <input type="text" readonly value="Read-only content">
  <input type="submit" value="Submit">
</form>
  • Styling: You can apply custom styling to indicate that a field is read-only, such as changing the background color or adding a different border style

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads