2

Possible Duplicate:
When to Use Double or Single Quotes in JavaScript
Are single quotes valid in HTML/XHTML?

In the world of XHTML, HTML, Javascript etc. does it matter if you use ' or " when writing code as long as you stick to one or the other? And is it better to use one over the other and why?

Community
  • 1
  • 1
L84
  • 45,514
  • 58
  • 177
  • 257
  • IMO it's largely preference. I use `"` when writing plain JavaScript, and `'` when inside a tag event handler attribute (which is rare enough these days). – Dave Newton Nov 08 '11 at 02:06
  • If this was asking about Javascript only it would be a duplicate but I am also asking about HTML and XHTML. – L84 Nov 08 '11 at 02:15

1 Answers1

1

being XML, XHTML will only take the double quote. HTML being SGML can take either. JavaScript, though, doesn't care as long as you are consistent withing a single string (that is opening and closing with the same character).

Dmitry B.
  • 9,107
  • 3
  • 43
  • 64
  • HTML does allow single quoted attributes. – Paul Nov 08 '11 at 02:11
  • Umm? [3.2.2 Attributes](http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.2) "By default, SGML requires that all attribute values be delimited using either double quotation marks (ASCII decimal 34) or single quotation marks (ASCII decimal 39)." – ephemient Nov 08 '11 at 02:12
  • my bad... it's being a while since I last looked at the SGML spec. Fixing the answer... – Dmitry B. Nov 08 '11 at 02:14
  • With XHTML Transitional will it take single `'` when XHTML Strict will not? – L84 Nov 08 '11 at 02:19
  • 1
    XML (including XHTML) also allows single or double-quotes. The idea that XML only allows double-quotes is widely believed but not true. Have a look at [the spec](http://www.w3.org/TR/REC-xml/#NT-AttValue) – nnnnnn Nov 08 '11 at 02:41
  • Either way, be it XHTML or HTML, it makes no sense to use single quotes. Double quotes are the standard, and should always be used. In JavaScript, I argue the same point, use double quotes always. It is easy enough to escape quotes. – SoWeLie Nov 08 '11 at 02:46