Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CSS Class Name Limitations? 1

Status
Not open for further replies.

JavaStripped

Programmer
Dec 18, 2002
84
CA
Specifically, which characters are and are not allowed in a class (or ID) name, and what is the maximum length for a class (or ID) name? I can't seem to find documentation on this anywhere... maybe I'm just looking in the wrong places.

Thanks for any clarification on this.

[yawn]
This is a question I shouldn't have needed to post. I think it's bedtime.


JavaStripped
"I did *not* escape. They gave me a day pass."
 
[ol]
[li]All CSS style sheets are case-insensitive, except for parts that are not under the control of CSS. I.e., in CSS1, font family names and URLs can be case-sensitive. Also, the case-sensitivity of the CLASS and ID attributes is under the control of HTML.
[li]in CSS1, selectors (element names, classes and IDs) can contain only the characters A-Z, 0-9, and Unicode characters 161-255, plus dash (-); they cannot start with a dash or a digit; they can also contain escaped characters and any Unicode character as a numeric code (see next item).
[li]the backslash followed by at most four hexadecimal digits (0..9A..F) stands for the Unicode character with that number.
[li]any character except a hexadecimal digit can be escaped to remove its special meaning, by putting a backslash in front, Example: "\"" is a string consisting of one double quote.
[li]the two preceding items define backslash-escapes. Backslash-escapes are always considered to be part of an identifier, except inside strings (i.e., "\7B" is not punctuation, even though "{" is, and "\32" is allowed at the start of a class name, even though "2" is not).
[/ol]
From . I couldn't find a maximum length, it might be a browser-dependent thing. How long would you want them anyway?

-- Chris Hunt
Extra Connections Ltd
 
Thanks for the details on character legality, Chris. I wasn't *really* worried about the length; it's just that I had a number of class names getting rather long (around 20 characters), and I wanted to make sure I wasn't going to run into problems if (for some horrible reason) they got much longer.

Thanks again,


JavaStripped
"I did *not* escape. They gave me a day pass."
 
JavaStripped,

Regarding size of selector names, though there might be no theoretical limit there might be browser set limit.

Just like Internet Explorer limits the URL length at around 2000 characters but the theoretical limit is infinite.

I'm pretty sure that around 20-40 characters you'll be fine. Just be careful if you go past really crazy numbers though. Always test! :)

Gary Haran
==========================
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top