Skip to main content

HTML Guide

Attribute “readonly” is only allowed when the input type is “date”, “datetime-local”, “email”, “month”, “number”, “password”, “search”, “tel”, “text”, “time”, “url”, or “week”.

Remove the readonly attribute from unsupported input types or change the input’s type to one that allows readonly.

The readonly attribute is only valid for textual input controls where the user can select text but not modify it. Per the HTML standard and W3C validators, allowed types are: text, search, url, tel, email, password, date, month, week, time, datetime-local, and number. It is not permitted on types like checkbox, radio, range, color, file, button, submit, reset, image, or hidden. For non-textual inputs, use disabled to prevent interaction, or use scripting/ARIA patterns as appropriate. Remember that disabled fields are excluded from form submission, while readonly fields are submitted.

HTML Examples

Example that triggers the validator error

<input type="checkbox" name="agree" readonly>

Corrected examples

<!-- Use a supported type with readonly -->

<input type="text" name="code" value="ABC-123" readonly>

<!-- For non-text controls, use disabled if you need it non-interactive -->

<input type="checkbox" name="agree" disabled>

Learn more: