![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
What characters are permissible in (for example) id and class attributes? What happens when using characters that are used in HTML to encode other caharacters, such as '&'? Since HTML, XHTML and CSS are all different languages, I presume it's theoretically possible that the specification for one could allow characters in say a class name that wouldn't be permitted by another. |
#3
| |||
| |||
|
|
In article 1ibwkms.1v3lops1ik23w2N%real-not-anti-spam-address (AT) apple-juice (DOT) co.uk>, real-not-anti-spam-address (AT) apple-juice (DOT) co.uk (D.M. Procida) wrote: What characters are permissible in (for example) id and class attributes? What happens when using characters that are used in HTML to encode other caharacters, such as '&'? Since HTML, XHTML and CSS are all different languages, I presume it's theoretically possible that the specification for one could allow characters in say a class name that wouldn't be permitted by another. That's true. Why not have a look at the specs? Here's a list of HTML 4.01's attributes, with links to the formal definition of each: http://www.w3.org/TR/html4/index/attributes.html |
|
A glance at the CSS syntax makes it look as if the CSS rules for identifiers allow a superset of what's allowed in (X)HTML: http://www.w3.org/TR/CSS1#appendix-b |
#4
| |||
| |||
|
|
The answer I wanted is right there in: http://www.w3.org/TR/html4/types.html#type-cdata |
#5
| |||
| |||
|
| http://www.w3.org/TR/html4/types.html#type-cdata Unfortunately, it's not that simple. As you wrote in your question, "HTML, XHTML and CSS are all different languages". -?{nmstart}{nmchar}* with nmstart [_a-z]|{nonascii}|{escape} nmchar [_a-z0-9-]|{nonascii}|{escape} nonascii [\200-\377] escape {unicode}|\\[^\r\n\f0-9a-f] unicode \\{h}{1,6}(\r\n|[ \t\r\n\f])? This is understandable (well, decipherable) to anyone familiar with regular expressions - and plain gibberish to the rest of mankind, probably including well over 99% of all web authors. Anyway, this means that the correct answer to the question "what characters are allowed in class names by the specs?" is not simple at all. And the correct answer would not even be very helpful, since it does not address the question "which characters can we (safely) use in class names?". The short answer to _this_ question is "letters A thru Z and a thru z, digits 0 thru 9, and the Ascii hyphen '-'". The underline "_" is fairly safe, too, but it doesn't really have much benefit over the hyphen. |
#6
| |||
| |||
|
|
-?{nmstart}{nmchar}* with nmstart [_a-z]|{nonascii}|{escape} nmchar [_a-z0-9-]|{nonascii}|{escape} nonascii [\200-\377] escape {unicode}|\\[^\r\n\f0-9a-f] unicode \\{h}{1,6}(\r\n|[ \t\r\n\f])? .... Hmm. |
|
I was (partly) interested in finding out whether % signs were permitted. |
|
And as far as the validators I tried were concerned, they were happy with a class="10%", for example. |
![]() |
| Thread Tools | |
| Display Modes | |
| |