Question

For example: #_id-name {} and ._class-name {} I know that in the early days underscores were not allowed at all - as well as double hyphens (--). But is it OK and would all browsers be able to read/understand a class or an ID if it starts with an _?

Was it helpful?

Solution

I'm basing my answer on html rather than just CSS. Documentation:

To summarize, the id must apparently begin with a letter (A-Za-z) and can have any other letters, numbers, underscore, or dash after that. Practically, you can start the id with - or _ and it will work: http://jsfiddle.net/ExplosionPIlls/y6jvs/ but starting with a number does not work.

While these restrictions don't appear to apply to classes which are a CDATA list, practically it seems to work the same: http://jsfiddle.net/ExplosionPIlls/y6jvs/1/

So you get a consistent and future proof browser experience, I would try to avoid doing anything funky with IDs, class names, etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top