开发者

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

This question already has answers here: 开发者_如何学JAVA Are single quotes allowed in HTML? (11 answers) Single vs Double quotes (' vs ") (16 answers) Closed 5 years ago.

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?


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜