Whats the difference between & and & in HTML5? [duplicate]

我们两清 提交于 2019-12-06 05:37:49

In HTML5, they are equivalent in that example. Traditionally, in HTML, only & was correct — but as with so many things, web developers blithely ignored this inconvenient rule and wrote bare ampersands everywhere. For their part, browsers just "did the right thing" and interpreted these ampersands as ampersands. HTML5 standardized this behavior, so now & is allowed by itself as long as what goes afterward does not look like an entity reference.

& is the html special character for &, which has a special meaning as the sigial for html special characters. The fact that href="&" works is a convenience granted by most browsers who are nice enough to properly deal with invalid HTML, but it is technically incorrect. You want to use & because the entity will be converted into & in the HTML code.

Consider if you used " instead of &. That would end the href value and make the HTML incorrect, right? You want to use ".

See: http://www.w3.org/html/wg/drafts/html/master/single-page.html#syntax-errors "Errors involving fragile syntax constructs" -- in fact it points out that using & is okay if it's not followed by a named character reference, but there are many of those; ideally you would be escaping attribute input more or less automatically.

& is the html entity (encoded form) for &, used to describe an ampersand in languages where an ampersand actually means something, like XML.

HTML rendering tools, like the browser, will see & in the source but render &

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