40

Is it valid to use / in a class name in html/css?

// html
<div class="/10"></div>

// css
./10{ float:left; }
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
Adam Halasz
  • 57,421
  • 66
  • 149
  • 213
  • This will answer it http://stackoverflow.com/questions/448981/what-characters-are-valid-in-css-class-selectors – Vinay Pratap Singh Bhadauria Aug 28 '13 at 10:15
  • this symbol is not valid.For reference goto the above posted link.. – Sasidharan Aug 28 '13 at 10:16
  • Using non-alphanumeric chars in identifiers is always a bad idea no matter what. – Alex Aug 28 '13 at 10:16
  • myclass,myclass1,m1yclass are valid,1myclass is not valid. No symbols should not be added except underscore. – majorhavoc Aug 28 '13 at 10:17
  • You need to [escape the character](http://www.w3.org/TR/CSS2/syndata.html#escaped-characters), so it would need to be a blackslash `.\10` – Xareyo Aug 28 '13 at 10:20
  • 2
    @Sharath All your examples are perfectly valid, you just can't select the one starting with a number in CSS without escaping the leading character. http://jsfiddle.net/SgzCq/ – xec Aug 28 '13 at 10:20
  • Check this link: http://stackoverflow.com/questions/448981/what-characters-are-valid-in-css-class-selectors – Dheeraj Anand Aug 28 '13 at 10:27

1 Answers1

59

You can use most unicode characters in both the class and id attributes in HTML.

This means you can indeed use / in a classname in HTML, but you will run into problems when trying to select it with ./10 in CSS, as you've likely found out yourself. If you escape the slash, you're golden! :)

.\/10 {
    float:left;
}

Check out http://mathiasbynens.be/notes/html5-id-class and http://mathiasbynens.be/notes/css-escapes

xec
  • 17,349
  • 3
  • 46
  • 54