0

Possible Duplicate:
What characters are valid in CSS class names?

Don't if this is suppose to be like this, but when I specify a class: .3plans, it does not apply the styling. But when I change the class name to .plans, it recognizes the style. Why is that? Note that the .3plans class is unique and there is no other style like that in my sheet, so it cannot be a duplicate. Is this phenomenon a common CSS practice? (not to use numbers in styles)

Community
  • 1
  • 1
DextrousDave
  • 6,603
  • 35
  • 91
  • 134

4 Answers4

6

If class & ID is start from number then is not recognized by css. But you can write like this .plans3 instead of .3plans.

As per W3c

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, or a hyphen followed by a digit. Identifiers can also contain escaped characters and any ISO 10646 character as a numeric code (see next item). For instance, the identifier "B&W?" may be written as "B\&W\?" or "B\26 W\3F".

Check this discussion for more Which characters are valid in CSS class names/selectors?

Community
  • 1
  • 1
sandeep
  • 91,313
  • 23
  • 137
  • 155
3

This flumoxed me for a while till someone pointed this out. From the W3C:

In CSS2, identifiers (including element names, classes, and IDs in selectors) can contain only the characters [A-Za-z0-9] and ISO 10646 characters 161 and higher, plus the hyphen (-); they cannot start with a hyphen or a digit. They can also contain escaped characters and any ISO 10646 character as a numeric code (see next item). For instance, the identifier “B&W?” may be written as “B\&W\?” or “B\26 W\3F”.

SpaceBeers
  • 13,617
  • 6
  • 47
  • 61
1

Basically a name must begin with an underscore (_), a dash (-), or a letter(a–z), followed by any number of dashes, underscores, letters, or numbers.

Now check more info http://www.w3.org/TR/CSS21/grammar.html#scanner

Rohit Azad Malik
  • 31,410
  • 17
  • 69
  • 97
1

A class name can start with a digit, but then you have to write the digit as an escape code:

.\33plans { ... }

33 is the hexadecimal character code for the character 3.

The W3C CSS validation service says:

"In CSS1, a class name could start with a digit (".55ft"), unless it was a dimension (".55in"). In CSS2, such classes are parsed as unknown dimensions (to allow for future additions of new units) To make "3plans" a valid class, CSS2 requires the first digit to be escaped ".\33plans" [3plans]"

Guffa
  • 687,336
  • 108
  • 737
  • 1,005