Difference between :disabled and :readonly in HTML?


Viewed 60,985 times


Usually both have similar behaviors when rendered in the browser.

If I open an HTML with this:

<input type="text" value="tente me alterar" disabled>
<input type="text" value="tente me alterar" readonly>

Both do not allow the user to change the text, see the example below:

 <input type="text" value="tente me alterar" disabled>
 <input type="text" value="tente me alterar" readonly>

So what’s the difference between the two types of states, and when I should use each of them?

4 answers


Disabled does not pass the value to the user, and can not edit.

Readonly sends the value to the form and also cannot edit.

Assuming you have this html:

<form method="post" action="page.php">
    <input type="text" name="foo" value="foo" disabled="disabled" />
    <input type="text" name="bar" value="bar" readonly="readonly" />

Your page 'page php.' will receive only the $_POST['bar']

  • 1

    Another difference is that the default look of the two is different.


Disabled you cannot edit or get input value while processing the Form.

Readonly you can at least take the value of the input in the Form processing.

This is the basics. There are a few more nuances:

  • In the Disabled you cannot select the field value to copy it, unlike the Readonly;
  • In the Disabled Tab Cursor does not stop in the field, unlike Readonly;
  • "Take" the value of input as a user, right? Because programmatically you can still ;)

  • Exactly. Let me make it better.

  • It worked for me too. Thanks!


Just to complement the replies of @mend3 and @Cigano Morrison Mendez.

Both disabled and readonly are predefined attributes, that is to say, they do not need to receive value for it to work.


<input type="text" placeholder="Apenas Disabled" disabled>
<input type="text" placeholder="Disabled true" disabled="true">
<input type="text" placeholder="Disabled false" disabled="false">
<input type="text" placeholder="Disabled goku" disabled="goku">
<input type="text" placeholder="Apenas readonly" readonly>
<input type="text" placeholder="Readonly true" readonly="true">
<input type="text" placeholder="Readonly false" readonly="false">
<input type="text" placeholder="Readonly goku" readonly="goku">

No point in false, values are ignored and the attribute acts as boolean, either this or this.



This boolean attribute indicates that the user cannot modify the value control. HTML5 This attribute is ignored if the attribute value type for Hidden, range, color, checkbox, radio, file or a type of button.


This boolean attribute indicates that the form control is not available for interaction. In particular the click event will not be fired on disabled controls. Also, the value of a disabled control is not sent with the form.

Source: Attributes of an element

Browser other questions tagged

You are not signed in. Login or sign up in order to post.