Search code examples
htmlformsreadonlyinput-field

What is the correct readonly attribute syntax for input text elements?


As Most, I am familiar with the readonly attribute for text input, But while reading code from other websites (a nasty habit of mine ) I saw more than one implementation for this attribute:

<input type="text" value="myvalue" class="class anotherclass" readonly >

and

<input type="text" value="myvalue" class="class anotherclass" readonly="readonly" >

and I have even seen

<input type="text" value="myvalue" class="class anotherclass" readonly="true" >

.. And I believe I saw even more, but can not recall the exact syntax now..

So, which one is the correct one that I should use?


Solution

  • From w3:

    readonly = "readonly" or "" (empty string) or empty - Specifies that element represents a control whose value is not meant to be edited.

    So basically it's the same.