I don't understand the HTML5 specifications for the lang
and xml:lang
attributes of the opening <开发者_C百科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?
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.
Since HTML5 is not XML, really, I personally would find it weird to use any xml:
namespace stuff.
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.
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.
To answer the question you originally had about 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.
Private Use Subtags are defined in at RFC: 5646, BCP 47 http://www.ietf.org/rfc/bcp/bcp47.txt
Section 2.2.7. Private Use Subtags
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.
Also check : https://www.w3.org/International/questions/qa-lang-why.en where some good reasons mentioned are:
- 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)
精彩评论