2

When I try to validate the following HTML:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>test page</title>
    </head>
    <body>
        <input type="text" name="testInput" value="test value" readonly="readonly" style="background-color: #e3e3e3;">
    </body>
</html>

The validator gives the error:

Line 8, Column 118: Attribute readonly not allowed on element input at this point.

But in the error details it says:

readonly when type is text, ...

As this is a text input, why am I receiving the validation error?

2
  • 1
    I'm wondering if it is a bug in the validator, as search and email work just fine. WHATWG confirms that readonly is valid here; it also states that text and search are nearly identical functionally, leading me to question further why the W3's validator would accept search but not text. Commented Apr 16, 2013 at 2:05
  • Yes, this is a bug. The validator.nu validator (which is based on the same code base) does not have it. Commented Apr 16, 2013 at 4:43

2 Answers 2

3

This is bug in the W3C Markup Validator; I have submitted a bug report.

While waiting for the bug to be fixed (which I expect to happen soon), use the validator.nu service instead.

Update: The bug has now been fixed.

Sign up to request clarification or add additional context in comments.

Comments

0

readonly attribute is only allowed on these input types:

  • text
  • search
  • url
  • tel
  • email
  • password
  • date
  • month
  • week
  • time
  • datetime-local
  • number

For any other input type like hidden, you are not allowed to have readonly in which case you may get:

Error: Attribute readonly not allowed on element input at this point.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.