-1

As per MDN attribute selector in css has the following syntax:

div[attr="actualValue"]

Or like this example:

<div class="test"></div>  

div[class="test"]

But I noticed that the quotes around the test are not needed as:

div[class=test]

Example:

div[class=test] {
  background: #6ea7b2;
}
<div class="test">I am a div</div>

Why is this? Does w3c spec allow attribute selection without quotes around the value?

user31782
  • 6,688
  • 11
  • 61
  • 127

1 Answers1

2

From the specification:

Attribute values must be CSS identifiers or strings.

"test" is a string, which is fine.

test is an identifier, which is fine.

Quentin
  • 857,932
  • 118
  • 1,152
  • 1,264
  • 1
    As to why? I presume it's for parity with HTML, which allows the same. (Bet half the people reading this didn't know that either.) – BoltClock Jul 08 '17 at 15:07