Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to specify an input field is read-only in HTML ?

  • Last Updated : 25 Dec, 2020

In this article, we will specify an input field is read-only in HTML. The readonly attribute of <input> element is used to specify that the input field is read-only. If an input is readonly, then it’s content cannot be changed but can be copied and highlighted. It is a boolean attribute.

Syntax:

Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.

<input readonly>

Example: This example using <input> readonly attribute to set the read-only value.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <title>
        How to specify an input
        field is read-only in HTML?
    </title>
</head>
  
<body style="text-align:center">
    <h1 style="color: green;">
        GeeksforGeeks
    </h1>
  
    <h2>
        How to specify an input
        field is read-only in HTML?
    </h2>
  
    <label>Input Value:
  
        <!--A readonly input-->
        <input type="text" name="value" 
            value="This input field is readonly"
            readonly>
    </label>
</body>
  
</html>

Output:

My Personal Notes arrow_drop_up
Recommended Articles
Page :