What Quotation Marks Should I Use In CSS? [duplicate]
Asked Answered
D

3

7

Possible Duplicate:
Which type of quotes we should use in css background url (“…”)? Single, double or no quote needed?

Simple question. What quotation marks should I use in CSS?

Option #1:

background: url( 'foo.png' );

Option #2:

background: url( "foo.png" );

Both works on "normal browsers". I just want to follow the standards.

Deidradeidre answered 16/4, 2011 at 17:30 Comment(0)
R
16

The standards say:

The format of a URI value is 'url(' followed by optional white space followed by an optional single quote (') or double quote (") character followed by the URI itself, followed by an optional single quote (') or double quote (") character followed by optional white space followed by ')'. The two quote characters must be the same.

i.e. none, single or double. If you care about IE5/Mac (which you probably don't these days) avoid ', otherwise use whatever makes you comfortable.

Retake answered 16/4, 2011 at 17:31 Comment(1)
Was going to post almost exactly the same answer - only thing I'd add is that the same definition holds for strings in general w3.org/TR/2008/REC-CSS2-20080411/syndata.html#stringsCioffi
S
3

The standard is that you can use either for strings, and you can use either or neither for URLs. For the most part there's no real difference, but if the value you're trying to quote has double-quotes in it then it's easier to use single-quotes, and vice-versa.

Besides that, you're welcome to prefer one or the other consistently if you think it makes your files nicer and easier to edit, but nobody will shoot you for using the "wrong" one.

Snappy answered 16/4, 2011 at 17:34 Comment(0)
N
0

I use double quotes...That's how I've seen it in books and tutorials. Just be consistent in your own work

Newness answered 16/4, 2011 at 17:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.