Does & need to be & in the meta description?

你。 提交于 2019-11-28 02:59:20

问题


I'm inserting content which has the & sign. I would like to know if it's needed to insert it as & so this sign is read correctly.

Like this:

<meta name="description" content="lorem lorem S&amp;B lorem lorem">

Or like this:

<meta name="description" content="lorem lorem S&B lorem lorem">

回答1:


You always represent an ampersand in HTML content as &amp; or &#38;, never a bare &. This includes both text between an element's tags, as well as attribute values. No exceptions.

This is because & itself denotes the start of an HTML entity reference (as seen above) and can often cause problems when appearing in the middle of text that could be interpreted as an entity reference.




回答2:


In HTML5, you are not allowed to use "ambiguous ampersands" in attribute values:

Attribute values are a mixture of text and character references, except with the additional restriction that the text cannot contain an ambiguous ampersand.

An ambiguous ampersand is defined as:

[…] a U+0026 AMPERSAND character (&) that is followed by one or more alphanumeric ASCII characters, followed by a ";" (U+003B) character, where these characters do not match any of the names given in the named character references section.

In your example (&B lorem), the ampersand (&) is followed by an alphanumeric ASCII character (B), but this one is not followed by a semicolon (;). So your ampersand is not ambiguous.

Which means that both of your examples are valid.




回答3:


It depends on the search engine. Google tends to pick this up as a string so you would want to add &amp; and other related ascii codes.

I recommend due to web standards that you always write an ampersand as &amp;



来源:https://stackoverflow.com/questions/20585754/does-need-to-be-amp-in-the-meta-description

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