HTML <input> Tag with the 'readonly' Attribute

<form name="myForm" action="http://www.htmlcodes.ws/resources/html-forms-action.cfm">
	
<input name="myInput" value="Read only text" readonly>

<button>Submit</button>

</form>

The above example demonstrates usage of the <input> element with the readonly attribute.

The readonly attribute allows you to specify whether or not the user can edit the form control.

readonly vs disabled

The difference between readonly and disabled is that readonly is still focasable and allows the user to select the text etc, whereas disabled doesn't.

Boolean Attribute

The readonly attribute is a boolean attribute. If the attribute is present, its value must either be the empty string or a value that is an ASCII case-insensitive match for the attribute's canonical name, with no leading or trailing whitespace (i.e. either readonly or readonly="readonly").

Possible values:

  • [Empty string]
  • readonly