The serialization of a group of selectors is the concatenation of the serialization in parsing order of each individual selector in the group separated by a comma "," and a space (U+0020).
The serialization of a selector is the concatenation of the serialization in parsing order of each sequence of simple selectors in the selector separated by a space (U+0020) if the combinator is not the descendant combinator, the serialization of the combinator separating the sequence and the next one in selector parsing order, another space (U+0020) if the combinator is not the descendant combinator. The serialization of the pseudo-element potentially appended to the last sequence of simple selectors in the selector is appended to the serialization of the selector.
The serialization of a combinator is defined as a space (U+0020) for the descendant combinator, ">" for the child combinator, "+" for the adjacent sibling combinator, "-" for the general sibling combinator.
The serialization of a sequence of simple selectors is the
concatenation of the serialization in parsing order of all the
simple selectors in the sequence. A "*
" (U+002A) will be prepended if no universal selector or type
element selector is present in the sequence of simple selectors.
The serialization of a pseudo-element is the concatenation of "::" (U+002E U+002E) and the escaped pseudo-element name.
If the namespace prefix maps to a namespace
that is not the default namespace and is not the
null namespace (not in a namespace): the escaped namespace
prefix, followed by a "|
" (U+007C).
If the namespace prefix maps to a namespace
that is the null namespace (not in a namespace): "|
"
(U+007C).
If this is a type selector: the escaped element name.
If this is a universal selector: "*
" (U+002A).
The serialization of an attribute selector is the concatenation of
"[
" (U+005B)
If the namespace prefix maps to a namespace
that is not the null namespace (not in a namespace), the
escaped namespace prefix, followed by a "|
"
(U+007C)
If the namespace prefix maps to a namespace that is the null
namespace (not in a namespace), "|
" (U+007C)
The escaped attribute name
If there is an attribute value specified, "=
", "~=
",
"|=
", "^=
", "$=
", or "*=
"
as appropriate (depending on the type of attribute selector),
followed by the string escaped attribute value
"]
" (U+005D)
The serialization of a class selector is the concatenation of a "." (U+002E) and the escaped class name.
The serialization of an ID selector is the concatenation of a "#" (U+0023) and the escaped ID.
The serialization of a pseudo-class taking no argument is the concatenation of a ":" (U+003A) and the escaped pseudo-class name.
The serialization of a language pseudo-class is the concatenation
of a ":" (U+003A), the escaped pseudo-class name, a
"(
" (U+0028), the escaped argument of the
pseudo-class and finally a ")
" (U+0029).
The serialization of such a pseudo-class is the concatenation
of a ":" (U+003A), the escaped pseudo-class name, a "(
"
(U+0028), the serialization of the argument and finally a ")
"
(U+0029).
The serialization of the argument of the pseudo-class is as follows:
If the value is odd let it be "2n+1
".
If the value is even let it be "2n
".
If a is zero let it be b serialized as <integer>.
If a is one or minus one and b is zero let it be "n
"
(U+006E).
If a is one or minus one let the value
be "n
" (U+006E), followed by "+
"
(U+002B) if b is positive, followed by b serialized as <integer>.
If b is zero let the value be a serialized as <integer>, followed by
"n
" (U+006E).
Otherwise let the value be a serialized
as <integer>, followed by "n
"
(U+006E), followed by "+
" (U+002B) if b is positive, followed by b
serialized as <integer>.
The serialization of a language pseudo-class is the concatenation
of a ":" (U+003A), the escaped pseudo-class name, a "(
"
(U+0028), the serialization of the simple selector being the
argument of the pseudo-class and finally a
")
" (U+0029).