HTML5 <html> attributes xmlns, lang, xml:lang

后端 未结 3 2140
眼角桃花
眼角桃花 2020-12-29 21:36

I don\'t understand the HTML5 specifications for the lang and xml:lang attributes of the opening tag. Scrolling up a bit, I understand that x

相关标签:
3条回答
  • 2020-12-29 22:33

    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)
    0 讨论(0)
  • 2020-12-29 22:36

    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

    0 讨论(0)
  • 2020-12-29 22:38

    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.

    0 讨论(0)
提交回复
热议问题