2

I want to know whether numbers(only) can be used for naming a css class

is this valid?

.2{
  display:block;
}
Rajasekar
  • 18,392
  • 34
  • 106
  • 137

5 Answers5

2

No, it's not valid. But the more important fact is that you shouldn't define classes with no meaning as that doesn't make any sense when looking at writing semantic markup.

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 "2x" a valid class, CSS2 requires the first digit to be escaped ".\32x" [2x]

CSS Validator

damian
  • 5,314
  • 5
  • 34
  • 63
0

No you can't, it throw the selector rule exception. its like declaring a variable in c or cpp... if u declare as 2 then its not a variable, its a constant. because int num=2; this is always correct form but string 2=num; is always wrong in programming. Read more from http://www.w3.org/TR/CSS21/selector.html

vino20
  • 429
  • 4
  • 13
0

No you can not use only numbers as a css3 class name. but check this link out.

here

Community
  • 1
  • 1
Carsten Løvbo Andersen
  • 26,637
  • 10
  • 47
  • 77
0

No not possible

you can use like

._2{
}
or like 

.a2{
}
Sarath
  • 608
  • 4
  • 12
0

No,it's not working.

a lot of language is not support the first word is number.

Maybe you can use .menu-1