- Attribute of
- Input As The Fundamental Form Element In HTML: Here's What It Does
- What does
- Disables the input field.
<form> <label for="disabled">Disabled</label><br> <input name="disabled" value="You cannot edit me." disabled> </form>
readonly attributes have similar effects — in fact, they look the same from the user's perspective. In both cases, what the user sees is a field that is slightly “grayed out”, which cannot be clicked on or edited.
<form> <label for="disabled">Disabled</label><br> <input name="disabled" value="disabled" disabled> <br><br> <label for="readonly">Readonly</label><br> <input name="readonly" value="readonly" readonly> </form>
However, they are different and using the wrong one can cause problems.
If a field is
disabled, the value of the field is not sent to the server when the form is submitted. If a field is
readonly, the value is sent to the server.
disabledattribute and send whatever form data they like. This is true of any element, actually — never forget to consider server-side form validation and sanitizing.
Browser Support for disabled