Uses for the '"' entity in HTML

后端 未结 5 624
星月不相逢
星月不相逢 2020-12-02 13:00

I am revising some XHTML files authored by another party. As part of this effort, I am doing some bulk editing via Linq to XML.

I\'

5条回答
  •  旧巷少年郎
    2020-12-02 13:47

    It is impossible, and unnecessary, to know the motivation for using " in element content, but possible motives include: misunderstanding of HTML rules; use of software that generates such code (probably because its author thought it was “safer”); and misunderstanding of the meaning of ": many people seem to think it produces “smart quotes” (they apparently never looked at the actual results).

    Anyway, there is never any need to use " in element content in HTML (XHTML or any other HTML version). There is nothing in any HTML specification that would assign any special meaning to the plain character " there.

    As the question says, it has its role in attribute values, but even in them, it is mostly simpler to just use single quotes as delimiters if the value contains a double quote, e.g. alt='Greeting: "Hello, World!"' or, if you are allowed to correct errors in natural language texts, to use proper quotation marks, e.g. alt="Greeting: “Hello, World!”"

提交回复
热议问题