Special characters in CSS selectors

In CSS, identifiers (including element names, classes, and IDs in selectors) can contain only the characters [a-zA-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).code (see next item).

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


Normally, you wouldn't need to escape any special characters in CSS. This is because most CSS selector characters (., >, +, ~, #, :, etc) are not valid in id attributes or tag names, and they are rarely used in class names.

The only notable exception is a namespaced element in the form <ns:tagName>, which is more commonly seen in Internet Explorer. To target those elements, you can escape the : character. For example, VML objects have their behavior defined as follows:

v\:* { behavior: url(#default#vml); }