Is the value attribute in html subject to the same restrictions as the id attribute? Specifically, can I have a numeric value attribute.
-
1Any specific element you are talking about? What version of HTML?Oded– Oded2011-12-16 10:00:07 +00:00Commented Dec 16, 2011 at 10:00
-
Checkboxes in this specific casefearofawhackplanet– fearofawhackplanet2011-12-16 10:17:52 +00:00Commented Dec 16, 2011 at 10:17
2 Answers
Looking at the list of attributes for HTML 4, it appears that there is no restriction, apart from the LI element which requires it to be a number.
Update - since checkboxes (which are the element you have indicated in a comment) are INPUT elements, they have no special restriction. They can be any valid CDATA.
Comments
As you can see here, the value-attribute of an input-tag can be described as of type text which pretty much means 'no restrictions', whereas the value of the id-attribute is restricted:
Naming rules fo the id-attribute:
- Must begin with a letter A-Z or a-z
- Can be followed by: letters (A-Za-z), digits (0-9), hyphens ("-"), and underscores ("_")
- In HTML, all values are case-insensitive
Furthermore, I guess it would not make much sense to restrict the value-attribute in any kind because it represents user-input.
//EDIT:
To avoid w3schools being the only reference (shame on me, but I'm not deleting it in order to keep it as a monument for my rash act), here's a reference to w3.org about the input-tag and the data-type of its value-attribute. But I'm in trouble now, because both references tell different stories. According to w3schools, the data-type of the value-attribute is Text. But according to w3.org (which I sure trust more) the data-type is CDATA which comes along with a few general restrictions, e.g.:
User agents may ignore leading and trailing white space in CDATA attribute values (e.g., " myval " may be interpreted as "myval"). Authors should not declare attribute values with leading or trailing white space.
(http://www.w3.org/TR/html4/types.html#type-cdata)
And there's also a specific restriction for the id-attribute:
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").