Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html valid input value attributes

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

like image 453
fearofawhackplanet Avatar asked Feb 16 '26 06:02

fearofawhackplanet


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.

like image 110
Oded Avatar answered Feb 17 '26 22:02

Oded


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 (".").

like image 33
Quasdunk Avatar answered Feb 18 '26 00:02

Quasdunk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!