是“字符集"吗?HTML5 需要元标记吗? [英] Is the "charset" meta tag required with HTML5?

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

问题描述

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

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

对于 HTML 语法,作者需要声明字符编码.

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

什么是必需"?是什么意思?

What does "required" mean?

显然,浏览器仍会在没有 charset 元标记的情况下呈现 HTML5.如果没有指定编码,浏览器将使用哪种编码?

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

基本上,我想知道是否真的有必要包含 <meta charset=">>,或者浏览器是否在 99% 的情况下都会使用正确的编码.

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.

推荐答案

不必包含 .正如规范所说,字符集也可以由服务器使用 HTTP Content-Type 标头或通过在下载文件的开头包含 Unicode BOM 来指定.

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.

如果没有指定,今天的大多数网络服务器将在 Content-Type 标头中为 HTML 文本数据发回一个字符集.如果 Web 服务器没有发回带有 Content-Type 标头的字符集,则文件不包含 BOM 页面不包含 <meta charset="blah"> 声明,浏览器将具有通常基于主机语言设置的默认编码.如果这与文件的实际字符编码不匹配,那么某些字符将无法正常显示.

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.

浏览器会在 99% 的情况下使用正确的编码吗?如果您的页面是 UTF-8,可能.如果没有,可能没有.

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

W3C 提供了一个文档概述了三种方法的优先规则表示顺序是 HTTP 标头、BOM,然后是文档内规范(元标记).

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 需要元标记吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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