Class lengths and names
Does anyone know if there is a max length for class names? Of course I am not aiming for them to be big (just having to potentially deal with them).
A database I'm working with is spitting out some long class names on some list items that I am trying to do image replacement on. I think the longest one is 22 characters. Not sure I can make the class names small at this point as they are needed for other areas of the site.
Also, I know ID's can't start with numbers, but does the same apply to classes?
Ta folks. :D
I don't think there's a limit. Just searched google and nobody seems to have posted about it and can't find any spec info on it (via google). 22 characters should be fine.
Neither IDs or classes can start with numbers.
There doesn't seem to be a lot of information about this as Raffles said and I guess it will be down to each browser concerned. I just did a few quick tests with IE, Firefox and Opera and they seem to handle thousands of characters :)
Yeah, I've never run into any problems so think you're fine, certainly at 22 characters.
I also dealt with an accessibility company in the past who advised not to use underscores in ID or class names as earlier versions of Opera didn't support them. Probably not an issue nowadays as I presume we're talking about something around Opera 4 but even so I avoid using them as camelcase or dash is just as easy to use.
Super! Thanks guys. :)
I did some Googling and couldn't find anything and though I'd just post on here in case someone else knew something Google didn't :D
Thats is incorrect, only ID fits that rule. CLASS values are CDATA which can contain anything.
Originally Posted by Raffles
The spec has no restriction on CLASS like it does for ID and NAME.
Not according to the CSS specs :)
Thats is incorrect,
If you try using a digit at the start of the classname the style will be ignored.
Well I wasn't reading the CSS spec at the time :p
So in HTML it is valid but for CSS it is not...okay understood.