Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

lang

I usually use this: <html lang="en">.

However, I am working on a website that will use two languages and mix them up sometimes in the same sentence or heading.

How would the above code look in this case? Can I use <html lang="lang1 lang2">?

like image 455
Francisc Avatar asked Aug 16 '11 10:08

Francisc


People also ask

How do you use the lang attribute with more than one language?

If your intended audience speaks more than one language, the HTTP header allows you to use a comma-separated list of languages. Please Note: since you should always use a language attribute on the html tag, and the language attribute always overrides the HTTP header information, this really becomes a fine point.

How do you serve multiple languages in html?

To change the language, just simply set the lang attribute. We can define it anywhere in the document, such as in the body, in the paragraph, in the heading, or in the span tag. But the best practice is to set the lang in the span tag.

Which html attribute is used to define language of page?

You should always include the lang attribute inside the <html> tag, to declare the language of the Web page.

How should I set the language of the content in my html page?

Always add a lang attribute to the html tag to set the default language of your page. If this is XHTML 1. x or an HTML5 polyglot document served as XML, you should also use the xml:lang attribute (with the same value).


2 Answers

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>
like image 114
Jamie Dixon Avatar answered Oct 07 '22 08:10

Jamie Dixon


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.

like image 7
user11448 Avatar answered Oct 07 '22 08:10

user11448