Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the rules for HTML attribute values?

Tags:

html

When declaring an attribute value such as id="attributeValue" are there any particular rules on what characters are/aren't allowed?

I have always assumed that the first letter must always be a letter (a-z or A-Z) followed by pretty much any character(s). Then I realised this is the rules for declaring PHP variables

So what are the rules for declaring an attribute, and are they the same for all attributes e.g. id, name, href, type etc

like image 951
Michael Avatar asked Apr 25 '26 18:04

Michael


1 Answers

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

http://www.w3.org/TR/html401/types.html#h-6.2

So, your assumptions is pretty good, but "followed by pretty much any characters" is a bit optimistic.

like image 77
Guffa Avatar answered Apr 28 '26 04:04

Guffa



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!