Are single quotes valid in HTML/XHTML?

非 Y 不嫁゛ 提交于 2019-11-28 01:47:21

Yes, single quotes are valid.

From the XML spec:

[10]   AttValue  ::= '"' ([^<&"] | Reference)* '"'
                  |  "'" ([^<&'] | Reference)* "'"

A source of confusion on this matter seems to come from this article,

http://www.javascriptkit.com/howto/xhtml_intro.shtml

which seems to claim that single quotes are not valid in xhtml. However, since no specification is cited, and since the article also claims that lowercase names for attributes and elements are forbidden, the author may merely be expressing an editorial prohibition against using single quotes.

According to the spec, both are valid :-)

[9]    EntityValue    ::=    '"' ([^%&"] | PEReference | Reference)* '"'  
   |  "'" ([^%&'] | PEReference | Reference)* "'" 
[10]    AttValue    ::=    '"' ([^<&"] | Reference)* '"'  
   |  "'" ([^<&'] | Reference)* "'" 
[11]    SystemLiteral    ::=    ('"' [^"]* '"') | ("'" [^']* "'")  
[12]    PubidLiteral    ::=    '"' PubidChar* '"' | "'" (PubidChar - "'")* "'"

And the W3C-Validator accepts it as well.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!