HTML5 <html> 属性 xmlns, lang, xml:lang
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4320161/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTML5 <html> attributes xmlns, lang, xml:lang
提问by ma11hew28
I don't understand the HTML5 specifications for the lang
and xml:lang
attributesof the opening <html>
tag. Scrolling up a bit, I understand that xmlns
is a "talisman" (has no effect), but what about lang
and xml:lang
? Should they be used? If so, what should they be set to?
我不了解开始标记的lang
和xml:lang
属性的HTML5 规范<html>
。向上滚动一点,我知道这xmlns
是一个“护身符”(没有效果),但是lang
andxml:lang
呢?应该使用它们吗?如果是这样,它们应该设置为什么?
回答by Pointy
Everything I've seen and heard suggests that you should stick to
我所见所闻的一切都表明你应该坚持
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
(or whatever character set you actually want). If you want a language associated with the page you can use the "lang" attribute on the <html>
tag.
(或您真正想要的任何字符集)。如果您想要一种与页面相关联的语言,您可以使用<html>
标签上的“lang”属性。
Since HTML5 is notXML, really, I personally would find it weird to use any xml:
namespace stuff.
由于 HTML5不是XML,真的,我个人会觉得使用任何xml:
命名空间的东西都很奇怪。
回答by Alohci
xml:lang in the text/html serialization is just there to allow authors to write polyglot documents - documents that are valid XHTML5 and valid HTML5.
text/html 序列化中的 xml:lang 只是为了允许作者编写多语言文档 - 有效 XHTML5 和有效 HTML5 的文档。
In HTML (as opposed to XHTML), xml:lang is not an attribute in the XML namespace at all, it's an attribute in the null namespace called xml:lang
. i.e. the colon has no magic properties at all, it's just another character in the attribute name like any other.
在 HTML(与 XHTML 相对)中, xml:lang 根本不是 XML 命名空间中的属性,它是名为xml:lang
. 即冒号根本没有魔法属性,它只是属性名称中的另一个字符,就像任何其他字符一样。
To answer the question you originally had about en-US-x-hixie
:
要回答您最初提出的问题en-US-x-hixie
:
en-US-x-hixie
is en-US
(i.e. American English) plus a private use subtag -x-hixie
meaning the variant of US English as written by Ian Hickson, the editor of HTML5.
en-US-x-hixie
is en-US
(即美国英语)加上一个私人使用子标签,-x-hixie
意思是美国英语的变体,由 HTML5 的编辑 Ian Hickson 编写。
Private Use Subtags are defined in at RFC: 5646, BCP 47 http://www.ietf.org/rfc/bcp/bcp47.txtSection 2.2.7. Private Use Subtags
私有使用子标签在 RFC: 5646, BCP 47 http://www.ietf.org/rfc/bcp/bcp47.txt部分定义2.2.7. Private Use Subtags
回答by Nasia Makrygianni
The lang attribute makes huge a difference on a html document when it comes to users that use a screen reader. So considering a11y you would definitely want to use it. This video is the best argument on this: https://youtu.be/0uzxu9dQnuU"Effect of lang attribute on JAWS speech". It shows how a screen reader will pronounce english text with spanish,french or german pronunciation (which is very hard to understand) just because the lang attr is set to those languages each time.
当涉及到使用屏幕阅读器的用户时, lang 属性对 html 文档产生了巨大的影响。因此,考虑到 a11y,您肯定会想要使用它。此视频是对此的最佳论据:https: //youtu.be/0uzxu9dQnuU“lang 属性对 JAWS 语音的影响”。它显示了屏幕阅读器将如何使用西班牙语、法语或德语发音(这很难理解)来发音英语文本,因为 lang attr 每次都设置为这些语言。
Also check : https://www.w3.org/International/questions/qa-lang-why.enwhere some good reasons mentioned are:
还要检查:https: //www.w3.org/International/questions/qa-lang-why.en其中提到的一些很好的理由是:
- Styling (for example different fonts for different languages)
- Spelling and grammar checkers
- Translation tools
- Search results (page internal markup can be used to improve the quality of them based on the user's linguistic preferences)
- 样式(例如不同语言的不同字体)
- 拼写和语法检查器
- 翻译工具
- 搜索结果(页面内部标记可用于根据用户的语言偏好提高其质量)