What <html lang=“”> attribute value should I use for a mixed language page?

丶灬走出姿态 提交于 2019-11-28 16:58:13
Jamie Dixon

As far as I can tell from reading the HTML5 spec the lang attribute:

value must be a valid BCP 47 language tag, or the empty string

Source: http://www.w3.org/TR/html5/dom.html#the-lang-and-xml:lang-attributes

There's no mention in the spec of an array of language strings and every example I've found uses a single language string.

This makes sense since really a given section can only be in one language unless we're creating a new hybrid language.

Since the lang attribute is valid on all HTML elements you can wrap your language specific code in a new tag in order to indicate its language.

<html lang="en">
[...]
<body>
<h1>I am a heading <span lang="de-DE">Eine Überschrift</span></h1>
</body>
</html>

As I understand it you should be able to use <html lang="mul"> to indicate Multiple languages.

Choose subtags from the IANA Language Subtag Registry.

Source; https://www.w3.org/TR/2007/NOTE-i18n-html-tech-lang-20070412/#ri20030112.224623362

There is a subtag in the list named Subtag: mul

Source: http://www.iana.org/assignments/language-subtag-registry/language-subtag-registry

However I don't think you will be able to specify exactly which languages you're mixing in the html element. However, as Jamie wrote, you can specify different lang attributes for different elements at the page.

There do exist four special language codes within ISO 639-3 and all of them are also valid within the IANA subtag registry; https://en.wikipedia.org/wiki/ISO_639-3#Special_codes

However, I doubt this have good support from search engines as Google.

You can use like this.

For HTML 5 use:

Please see 'Declaring character encoding in HTML' for more information about character encoding.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!