1

From browsing the web, it seems that CSS property values, like HTML property values, can be quoted or not. However, in JSFiddle, I can only get the CSS to work if the values are unquoted.

Here's the HTML example:

<div id="withQuotes">The CSS for this has quoted parameter values.</div>
<div id="withoutQuotes">The CSS for this has unquoted parameter values.</div>

And here's the CSS:

#withQuotes {
font-size:"x-large";
width:'100px';}

#withoutQuotes {
    font-size:x-large;
    width:100px;
}

The above is saved in http://jsfiddle.net/8EMyW/

Peter Alfvin
  • 28,599
  • 8
  • 68
  • 106

1 Answers1

7

No, CSS properties in general cannot be quoted. Some CSS properties can have quotes in their values though, like:

background: url('quoted/path');

Certain CSS properties also accept a string as their value, which of course must be surrounded by quotes. font-family is an example of a property which can accept a string.

Paul
  • 139,544
  • 27
  • 275
  • 264
  • 2
    And some require it under certain circumstances, e.g. `font-family: "Times New Roman", serif;` – Mark Parnell May 17 '13 at 04:52
  • I believe that it is not required though. You can backslash escape the spaces as well if you want. – Paul May 17 '13 at 05:13
  • 1
    No quotes are *required* in `font-family: "Times New Roman", serif;`, just recommended: http://www.w3.org/TR/CSS2/fonts.html#font-family-prop – Jukka K. Korpela May 17 '13 at 05:18
  • Interesting. Per that spec, "If a sequence of identifiers is given as a font family name, the computed value is the name converted to a string by joining all the identifiers in the sequence by single spaces." So to clarify what you stated, although quotes are recommended and not required, backslashes are not required either. That is, `font-family: Times New Roman, serif;` is legit. – Peter Alfvin May 17 '13 at 11:18
  • It's hard not to say "thank you" and hard not to apologize for what in retrospect seems like a stupid question that I should have avoided by finding and reading the CSS spec. ;-) For what it's worth, I was thrown by http://mathiasbynens.be/notes/unquoted-attribute-values, the embedded advice of "when in doubt, use quotes" and confusing "CSS attribute values" with "CSS property values". – Peter Alfvin May 17 '13 at 11:26