Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pipe Chars in HTML Classes

Tags:

css

xhtml

w3c

I couldn't find anything in the W3C docs that said pipe chars, |, aren't allowed, for instance:

<div class="class1|class2">

Don't worry about what I might be using it for. I was just wondering if it's "legal".

like image 367
Jason Avatar asked Jun 01 '10 22:06

Jason


3 Answers

The relevant rules can be found in w3c syndata tokenization section, though it's pretty difficult to conclude from there if pipe is valid or not, as per a glance, it seems that anything is valid for a selector, i.e.:

selector    : any+;
any         : [ IDENT | NUMBER | PERCENTAGE | DIMENSION | STRING
              | DELIM | URI | HASH | UNICODE-RANGE | INCLUDES
              | DASHMATCH | ':' | FUNCTION S* any* ')' 
              | '(' S* any* ')' | '[' S* any* ']' ] S*;
like image 134
azatoth Avatar answered Oct 20 '22 22:10

azatoth


It's legal HTML, since the datatype of class is CDATA. You will have a problem with CSS selectors, because the pipe is not a valid character for a selector.

like image 42
Marc Avatar answered Oct 21 '22 00:10

Marc


It is a valid character in a class name. In fact, I see a website using pipe ( | ) just for the sake of class separation. Which I think is a good practice for readability.

Screenshot classes with pipe

like image 35
AlbertSamuel Avatar answered Oct 20 '22 23:10

AlbertSamuel