HTML input readonly Attribute

The HTML input readonly attribute is used to declare an input element unmodifiable, though it still may be copied.

Let us see an example of Input readOnly property −


 Live Demo

<!DOCTYPE html>
<title>Input Email readOnly</title>
   form {
      margin: 0 auto;
      text-align: center;
   * {
      padding: 2px;
   input[type="button"] {
      border-radius: 10px;
<label for="EmailSelect">Contact Us :
<input type="email" id="EmailSelect" onclick="showErrorMsg()" value="" readOnly>
<input type="button" onclick="showMessage()" value="Copy Email Id">
<div id="divDisplay"></div>
   var divDisplay = document.getElementById("divDisplay");
   var inputEmail = document.getElementById("EmailSelect");
   divDisplay.textContent = 'Above email is read-only';
   function showMessage() {;
      divDisplay.textContent = 'Email Copied: '+inputEmail.value;
   function showErrorMsg(){
      divDisplay.textContent +=', This cannot be edited.'

This will produce the following output −

1) Before clicking ‘Copy Email Id’ button −

2) Clicking ‘Contact Us’ email field −

3) Clicking ‘Copy Email Id’ −