19

Is it acceptable to use single quotes around html attribute values like this:

<span class='classname'>Hi</span>

Instead of double quotes like this:

<span class="classname">Hi</span>

Who defines what's okay? W3C?

clickbait
  • 2,818
  • 1
  • 25
  • 61
Tim
  • 6,079
  • 8
  • 35
  • 41
  • 2
    Duplicates at least http://stackoverflow.com/questions/273354/html-single-quotes-a-problem and http://stackoverflow.com/questions/3338969/what-are-the-functional-differences-between-single-quoted-vs-double-quoted-html-a – PleaseStand Jan 02 '11 at 04:19

3 Answers3

22

Yes, that's acceptable. It works in browsers, and it's allowed by the specifications.

The HTML5 spec says:

In the HTML syntax, attributes can be specified in four different ways:

  1. empty attribute syntax
  2. unquoted attribute-value syntax
  3. single-quoted attribute-value syntax
  4. double-quoted attribute-value syntax

The HTML4 spec says:

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). Single quote marks can be included within the attribute value when the value is delimited by double quote marks, and vice versa.

Community
  • 1
  • 1
thirtydot
  • 224,678
  • 48
  • 389
  • 349
  • Is this an acceptable answer? HTML5 is no longer officially based on SGML, and even so, you don't specify whether HTML uses this default mode. – fabspro Jul 16 '12 at 11:48
  • Weird, I don't even remember writing this answer (and I usually remember). I've updated it. – thirtydot Jul 16 '12 at 12:01
  • Great edit. I only commented because I found this at the top of a google search, and I figured other people might be interested. – fabspro Jul 16 '12 at 13:30
0

Single quotes are and have always been completely kosher, according to the W3 specification. It's a markup/code style choice, nothing more.

drewblaisdell
  • 609
  • 5
  • 16
0

Yes, the W3C publishes HTML standards.

They also provide a validator at http://validator.w3.org/

the validator is ok with both for XHTML 1.0 Strict.

There is several HTML standards, so whether it’s "acceptable" entirely depends on which you're using. Furthermore collaborative projects may have a coding style which defines to use one or the other. Using " is de-facto standard, even if the HTML standard may allow ' as well.

Kissaki
  • 8,810
  • 5
  • 40
  • 42