Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it acceptable to use single quotes around values in HTML attributes? [duplicate]

Tags:

html

syntax

css

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?

like image 738
Tim Avatar asked Jan 02 '11 04:01

Tim


1 Answers

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.

like image 173
thirtydot Avatar answered Oct 12 '22 23:10

thirtydot