1

What is the difference between:

  • <input type="text" disabled>
  • <input type="text" disabled="true">
  • <input type="text" disabled=true>
  • <input type="text" disabled="1">
  • <input type="text" disabled=1>
  • They all produce the same result, which is a disabled text input. Fiddle.

    But which of them is the most (generally) correct / best one to use?

    chris97ong
    • 6,870
    • 7
    • 32
    • 52
    • [this link might also be usefull to you](http://stackoverflow.com/questions/6961526/correct-value-for-disabled-attribute) – Déjà vu Apr 10 '14 at 07:29
    • I'm happy with XHTML. I like it. I close things I open. I don't like HTML. I'm now always getting yelled at for leaving everything open. – Phix Apr 10 '14 at 07:29

    1 Answers1

    9

    Only the first one is valid. If you want to be compatible with XHTML, it should be disabled="disabled":

    Boolean attributes may legally take a single value: the name of the attribute itself (e.g., selected="selected").

    In HTML, boolean attributes may appear in minimized form -- the attribute's value appears alone in the element's start tag. Thus, selected may be set by writing:

    <OPTION selected>
    

    instead of:

    <OPTION selected="selected">
    

    Authors should be aware that many user agents only recognize the minimized form of boolean attributes and not the full form.

    http://www.w3.org/TR/REC-html40/intro/sgmltut.html#h-3.3.4.2


    In HTML5, the value can also be an empty string:

    If the attribute is present, its value must either be the empty string or a value that is a case-insensitive match for the attribute's canonical name, with no leading or trailing whitespace.

    it is considered to be equivalent to the form with any value.

    Felix Kling
    • 795,719
    • 175
    • 1,089
    • 1,143