为什么我们需要HTML头中的元内容类型标记?

时间:2021-11-26 22:26:09

Why do we need to include the meta content type tag in HTML head like this?

为什么我们需要像这样在HTML头中包含元内容类型标记?

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>

3 个解决方案

#1


17  

Whenever the webpage is been opened locally (from disk file system), the text/html part will instruct the webbrowser of which type the document is so that it knows how to parse it and the charset=UTF-8 will instruct the webbrowser which character encoding should be used to display the characters on the webpage so that it won't use the platform default encoding (which may not necessarily be the right one which would thus potentially end up as mojibake).

每当在本地打开网页时(从磁盘文件系统),text / html部分将指示webbrowser文件是哪种类型,以便它知道如何解析它,而charset = UTF-8将指示webbrowser哪个字符应使用编码来显示网页上的字符,以便它不会使用平台默认编码(可能不一定是正确的编码因此可能最终成为mojibake)。

Important detail is that this HTML meta header isn't been used when the page is served over the web by HTTP. Instead, the Content-Type one in the HTTP response header will be used. So if this lacks the charset=UTF-8 part while the content is actually decoded as UTF-8, then it will likely go mojibake. You can determine the Content-Type header with for example Firebug, in the Net panel.

重要的细节是,当通过HTTP在Web上提供页面时,未使用此HTML元标头。相反,将使用HTTP响应头中的Content-Type 1。因此,如果缺少charset = UTF-8部分,而内容实际上被解码为UTF-8,那么它可能会变成mojibake。您可以在“网络”面板中使用Firebug确定Content-Type标头。

为什么我们需要HTML头中的元内容类型标记?

#2


2  

Meta elements are typically used to specify page description, keywords, author of the document, last modified, and other metadata.

元元素通常用于指定页面描述,关键字,文档的作者,最后修改的元数据和其他元数据。

The meta tag you have posted, will instruct the browser to have text/html type of document with character set or language set to UTF-8.

您发布的元标记将指示浏览器具有文本/ html类型的文档,其中字符集或语言设置为UTF-8。

Used to declare the character set.

用于声明字符集。

The Meta Content Type tag is used to declare the character set of a website. It has become recommended to always use the Meta Content Type tag even if you use a DTD declaration above the Header. If you fail to do so, it may cause display problems. For instance, the document may use UTF-8 punctuation characters but is displayed in ISO or ASCII character sets. There are other benefits to using the Meta Content Type tag. Simply subscribe to our SEO Revolution Newsletter (nominal fee membership) to get the entire scoop of what the Meta Content Type tag can do for your site

Meta Content Type标签用于声明网站的字符集。即使您在标题上方使用DTD声明,也建议始终使用Meta Content Type标记。如果您没有这样做,可能会导致显示问题。例如,文档可能使用UTF-8标点符号,但以ISO或ASCII字符集显示。使用Meta Content Type标记还有其他好处。只需订阅我们的SEO革命新闻通讯(象征性费用会员)即可获得Meta Content Type标签可为您的网站做的全部内容

See this for more info:

有关详细信息,请参阅此

#3


2  

So that the browser would know how to decode the page - for example: depending on the language, the end-result may differ a lot.

这样浏览器就会知道如何解码页面 - 例如:根据语言的不同,最终结果可能会有很大不同。

#1


17  

Whenever the webpage is been opened locally (from disk file system), the text/html part will instruct the webbrowser of which type the document is so that it knows how to parse it and the charset=UTF-8 will instruct the webbrowser which character encoding should be used to display the characters on the webpage so that it won't use the platform default encoding (which may not necessarily be the right one which would thus potentially end up as mojibake).

每当在本地打开网页时(从磁盘文件系统),text / html部分将指示webbrowser文件是哪种类型,以便它知道如何解析它,而charset = UTF-8将指示webbrowser哪个字符应使用编码来显示网页上的字符,以便它不会使用平台默认编码(可能不一定是正确的编码因此可能最终成为mojibake)。

Important detail is that this HTML meta header isn't been used when the page is served over the web by HTTP. Instead, the Content-Type one in the HTTP response header will be used. So if this lacks the charset=UTF-8 part while the content is actually decoded as UTF-8, then it will likely go mojibake. You can determine the Content-Type header with for example Firebug, in the Net panel.

重要的细节是,当通过HTTP在Web上提供页面时,未使用此HTML元标头。相反,将使用HTTP响应头中的Content-Type 1。因此,如果缺少charset = UTF-8部分,而内容实际上被解码为UTF-8,那么它可能会变成mojibake。您可以在“网络”面板中使用Firebug确定Content-Type标头。

为什么我们需要HTML头中的元内容类型标记?

#2


2  

Meta elements are typically used to specify page description, keywords, author of the document, last modified, and other metadata.

元元素通常用于指定页面描述,关键字,文档的作者,最后修改的元数据和其他元数据。

The meta tag you have posted, will instruct the browser to have text/html type of document with character set or language set to UTF-8.

您发布的元标记将指示浏览器具有文本/ html类型的文档,其中字符集或语言设置为UTF-8。

Used to declare the character set.

用于声明字符集。

The Meta Content Type tag is used to declare the character set of a website. It has become recommended to always use the Meta Content Type tag even if you use a DTD declaration above the Header. If you fail to do so, it may cause display problems. For instance, the document may use UTF-8 punctuation characters but is displayed in ISO or ASCII character sets. There are other benefits to using the Meta Content Type tag. Simply subscribe to our SEO Revolution Newsletter (nominal fee membership) to get the entire scoop of what the Meta Content Type tag can do for your site

Meta Content Type标签用于声明网站的字符集。即使您在标题上方使用DTD声明,也建议始终使用Meta Content Type标记。如果您没有这样做,可能会导致显示问题。例如,文档可能使用UTF-8标点符号,但以ISO或ASCII字符集显示。使用Meta Content Type标记还有其他好处。只需订阅我们的SEO革命新闻通讯(象征性费用会员)即可获得Meta Content Type标签可为您的网站做的全部内容

See this for more info:

有关详细信息,请参阅此

#3


2  

So that the browser would know how to decode the page - for example: depending on the language, the end-result may differ a lot.

这样浏览器就会知道如何解码页面 - 例如:根据语言的不同,最终结果可能会有很大不同。