-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
  • 7,087
  • 14
  • 68
  • 143

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
  • 914,110
  • 126
  • 1,211
  • 1,335
  • 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