SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict webmistress's Avatar
    Join Date
    Aug 2002
    Location
    Derbyshire, UK
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.
    ****************
    The Webmistress

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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.

  3. #3
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    40,484
    Mentioned
    182 Post(s)
    Tagged
    6 Thread(s)
    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

  4. #4
    SitePoint Wizard bronze trophy DaveWoods's Avatar
    Join Date
    Dec 2004
    Location
    Derbyshire - UK
    Posts
    2,651
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  5. #5
    SitePoint Addict webmistress's Avatar
    Join Date
    Aug 2002
    Location
    Derbyshire, UK
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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
    ****************
    The Webmistress

  6. #6
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Raffles View Post
    ...Neither IDs or classes can start with numbers.
    Thats is incorrect, only ID fits that rule. CLASS values are CDATA which can contain anything.

    The spec has no restriction on CLASS like it does for ID and NAME.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  7. #7
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    40,484
    Mentioned
    182 Post(s)
    Tagged
    6 Thread(s)
    Thats is incorrect,
    Not according to the CSS specs

    http://www.w3.org/TR/CSS21/syndata.html#characters

    Quote Originally Posted by wc3
    In CSS, identifiers (including element names, classes, and IDs in selectors) can contain only the characters [a-z0-9] and ISO 10646 characters U+00A1 and higher, plus the hyphen (-) and the underscore (_); they cannot start with a digit,
    If you try using a digit at the start of the classname the style will be ignored.

  8. #8
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Well I wasn't reading the CSS spec at the time
    So in HTML it is valid but for CSS it is not...okay understood.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  9. #9
    SitePoint Addict webmistress's Avatar
    Join Date
    Aug 2002
    Location
    Derbyshire, UK
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nicely cleared up.
    ****************
    The Webmistress


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •