CSS 2.1 defines identifiers as
In CSS, identifiers can contain only the characters [a-zA-Z0-9] and ISO 10646 characters U+00A0 and higher, plus the hyphen (-) and the underscore (_); they cannot start with a digit, two hyphens, or a hyphen followed by a digit. Identifiers can also contain escaped characters and any ISO 10646 character as a numeric code.
Therefore, --
should be an invalid identifier, and thus #--
shouldn't select the element with id="--"
:
body { color: black }
#-- { color: red }
<p id="--">I should be black.</p>
Attribute values must be identifiers or strings.
But --
seems to work as an identifier for attribute values, at least on Firefox:
body { color: black }
[id=--] { color: red }
<p id="--">I am red on Firefox.</p>
Moreover, CSS.escape
has been modified to allow --
:
Minor changes has been made in Firefox 32, to match the spec and the evolution of the CSS syntax. The identifier now can begin with
--
and the second dash must not be escaped.
According to the Wayback Machine, the change happened between 19 and 30 Apr 2014:
6 Feb 2014 editor's draft, stored on 19 Apr 2014.
If the character is the second character and is "-" (U+002D) and the first character is "-" as well, then the escaped character.
30 Apr 2014 editor's draft, stored on 4 May 2014.
If the character [...] is "-" (U+002D) [...], then the character itself.
So, has some new CSS3 module changed the definition of identifiers, so that they can sometimes begin with --
, or what exactly is happening here?