I want to ask you how to properly use lang in HTML code. Im trying to have website in 2 langs en, pl.
<html lang="en">
<html lang="pl">
Is this way correct?
If the document’s primary language is in, say, Polish with large parts that are in English, then it should have <html lang="pl">
with <div lang="en">
or something around the English parts:
<html lang="pl">
…
<body>
[Polish content]
<div lang="en">
[English content]
</div>
[more Polish content]
<div lang="en">
[more English content]
</div>
[more Polish content]
…
Regardless the html
element should if possible always have a lang
value, per the HTML spec:
Authors are encouraged to specify a
lang
attribute on the roothtml
element, giving the document's language. This aids speech synthesis tools to determine what pronunciations to use, translation tools to determine what rules to use, and so forth.
But if a document is such a mix of languages that it can’t really be seen as having a single primary language, then the html
element still should have a lang
attribute, but with an empty value:
Setting the attribute to the empty string indicates that the primary language is unknown.
<html lang="">
…
<body>
<div lang="pl">
[Polish content]
</div>
<div lang="en">
[English content]
</div>
<div lang="pl">
[Polish content]
</div>
<div lang="en">
[English content]
</div>
…
For more detailed information on this, see the following W3C guides:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With