47

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

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

// css
./10{ float:left; }
7
  • 1
    This will answer it stackoverflow.com/questions/448981/… Commented Aug 28, 2013 at 10:15
  • 1
    this symbol is not valid.For reference goto the above posted link.. Commented Aug 28, 2013 at 10:16
  • Using non-alphanumeric chars in identifiers is always a bad idea no matter what. Commented Aug 28, 2013 at 10:16
  • myclass,myclass1,m1yclass are valid,1myclass is not valid. No symbols should not be added except underscore. Commented Aug 28, 2013 at 10:17
  • 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. jsfiddle.net/SgzCq Commented Aug 28, 2013 at 10:20

1 Answer 1

67

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.