HTML5是否需要charset元标记? [英] Is the charset meta tag required with HTML5?

查看:184
本文介绍了HTML5是否需要charset元标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

W3C HTML5与HTML4的区别工作草案指出:


对于HTML语法,作者必须声明字符编码。


required是什么意思?

显然,浏览器仍然会呈现HTML5而没有charset元标记。如果没有指定编码,浏览器会使用哪种编码?



基本上,我想知道是否确实需要包含< meta charset => ,或者99%的浏览器无论如何都会使用正确的编码。



这是链接:< a href =http://www.w3.org/TR/html5-diff/#character-encoding\"rel =noreferrer> http://www.w3.org/TR/html5-diff/#character-编码

解决方案

不需要包含< meta charset =blah > 。正如规范所说,字符集也可以由服务器使用HTTP Content-Type 标题或在下载文件的开始处包含一个Unicode BOM。 / p>

如果没有任何内容,今天的大多数Web服务器都会返回HTML文本数据的 Content-Type 标题中的字符集指定。如果Web服务器不发送带有 Content-Type 标题的字符集,则该文件不包含BOM 该页面不包含< meta charset =blah> 声明,浏览器将具有通常基于语言设置的默认编码的主机。如果这与文件的实际字符编码不匹配,则某些字符将显示不正确。



浏览器会在99%的时间使用正确的编码吗?如果你的页面是UTF-8,可能。如果没有,可能不会。



W3C提供了文档概述了三种方法的优先权规则,其中说明顺序是HTTP标题,BOM,然后是文档内规范(元标记)。


The W3C "HTML5 differences from HTML4" working draft states:

For the HTML syntax, authors are required to declare the character encoding.

What does "required" mean?

Obviously, a browser will still render HTML5 without the charset meta tag. If no encoding is specified, which encoding will a browser use?

Basically, I want to know if it is actually necessary to include <meta charset="">, or if 99% of the time browsers will use the correct encoding anyway.

Here is the link: http://www.w3.org/TR/html5-diff/#character-encoding

解决方案

It is not necessary to include <meta charset="blah">. As the specification says, the character set may also be specified by the server using the HTTP Content-Type header or by including a Unicode BOM at the beginning of the downloaded file.

Most web servers today will send back a character set in the Content-Type header for HTML text data if none is specified. If the web server doesn't send back a character set with the Content-Type header and the file does not include a BOM and the page does not include a <meta charset="blah"> declaration, the browser will have a default encoding that is usually based on the language settings of the host computer. If this does not match the actual character encoding of the file, then some characters will be displayed improperly.

Will browsers use the proper encoding 99% of the time? If your page is UTF-8, probably. If not, probably not.

The W3C provides a document outlining the precendence rules for the three methods that says the order is HTTP header, BOM, followed by in-document specification (meta tag).

这篇关于HTML5是否需要charset元标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆