2

Is the value attribute in html subject to the same restrictions as the id attribute? Specifically, can I have a numeric value attribute.

2
  • 1
    Any specific element you are talking about? What version of HTML? Commented Dec 16, 2011 at 10:00
  • Checkboxes in this specific case Commented Dec 16, 2011 at 10:17

2 Answers 2

6

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.

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

Comments

3

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:

  1. Must begin with a letter A-Z or a-z
  2. Can be followed by: letters (A-Za-z), digits (0-9), hyphens ("-"), and underscores ("_")
  3. 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 (".").

1 Comment

@Oded lol - yeah, I know, it has a bad reputation, but that's the first reference I've found, I'll look for better ones and edit it ;)

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.