Skip to content

Which input types should readonly affect constraint validation for? #8133

Closed

Description

@nt1m

Given this example:

data:text/html,<input type=range min=0 max=100 value=50><input type=range readonly min=0 max=100 value=50><style>input:in-range { appearance: none; border: 1px solid red; }</style>

:in-range seems to be affected by whether an input is readonly, which makes sense when you read:

Constraint validation: If the readonly attribute is specified on an input element, the element is barred from constraint validation.`
from https://html.spec.whatwg.org/multipage/input.html#the-readonly-attribute

but on the other hand, the spec says that readonly does not apply to input[type=range] : https://html.spec.whatwg.org/multipage/input.html#do-not-apply

By that logic, I would expect readonly to have no effect on the :in-range selector for input[type=range].

WebKit & Firefox & Chrome all (probably unintentionally) have this incoherency, it is worth a clarification on whether:

  1. readonly bars constraint validation from all input types (matches current behavior in all browsers, but incoherent)
  2. readonly bars constraint validation on supported input types (more logical IMHO)

Activity

  1. added
    agenda+
    on Jul 27, 2022
  2. added
    topic: forms
    on Jul 27, 2022
  3. annevk commented on Jul 27, 2022

    @annevk
    Member

    cc @whatwg/forms

  4. domenic commented on Jul 29, 2022

    @domenic
    Member

    I think a strict reading of the spec supports current browser behavior. "do not apply" is a boolean predicate, and what effects it has are determined by other parts of the spec, which consult that predicate.

    Just because "do not apply" = true for (<input type=range>, readonly=""), that doesn't mean "everything to do with readonly stops applying to <input type=range>". (For example, basic behaviors like the fact that rangeInput.setAttribute("readonly", "") causes rangeInput.hasAttribute("readonly") to return true, or rangeAttribute.matches("[readonly]"), still "apply".)

    So since the part of the spec defining :in-range doesn't consult the "do not apply" predicate, there's no impact.

    This could be clarified by renaming "do not apply" to something like "mostly doesn't apply" or "has most features disabled", I suppose, and explaining the above.

  5. removed
    agenda+
    on Aug 5, 2022
  6. added
    clarification
    on Aug 11, 2022
  7. added a commit that references this issue on Sep 5, 2022
  8. added a commit that references this issue on Sep 3, 2025
  9. cdoublev commented on Feb 12, 2026

    @cdoublev
    Contributor

    I think a strict reading of the spec supports current browser behavior.

    § 4.10.5.3 Common input element attributes requires user agents to ignore readonly when it does not apply to the input element.

    When an attribute doesn't apply to an input element, user agents must ignore the attribute, regardless of the requirements and definitions below.

    It does not say how much they must ignore it. The constraint validation added by the presence of readonly is one of the definitions below, whose section does not define much else.

    So instead of rewording do not apply, perhaps this paragraph could just be extended by adding an exception for when consulting the presence of the attribute, rather than consulting whether it applies on the input type.

  10. dbaron commented on Apr 3, 2026

    @dbaron
    Member

    #8089 (comment) reported general agreement with the proposal above in #8133 (comment)

    I think the spec could certainly use some clarification here, though. (And the current situation doesn't really make sense.)

  11. added a commit that references this issue on Nov 23, 2026
    546d834
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    clarificationtopic: forms

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions