The 'checked' Attribute of some HTML Elements


What Is Wrong with My "checked" Attribute Values?



Attribute "checked" is an optional attribute for HTML element "input". In XHTML specification, attribute "checked" has only one predefined value: "checked". However, in HTML specification, attribute "checked" requires no value.

If you are converting existing HTML documents to HTML format, you will get some syntax error on your pre-selected items in radio buttons, check boxes and dropdown lists, "checked" attributes are used without any values.

Here are some interesting examples of "checked" attributes:

  • <input type="radio" name="lang" value="HTML" checked> - Invalid, all attributes must have values. This is valid as HTML documents.
  • <input type="radio" name="lang" value="HTML" checked="yes"> - Invalid, "yes" is not the predefined value of attribute "checked".
  • <input type="radio" name="lang" value="HTML" checked="checked"> - Valid, attribute "checked" is assigned with predefined value "checked".


Introduction of HTML Element Content Syntax

Predefined HTML Attribute Values

HTML Tag and Attribute Syntax

⇑⇑ HTML Tutorials

2017-07-30, 1386🔥, 0💬