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?
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?
You can't have two <html>
tags in the same document. You should use one <html>
tag without the lang
attribute and use the lang
attribute on tags that contain only one language. Here is an example:
<html>
<head>
<!--some elements in the head-->
</head>
<body>
<p lang="en">This is text</p>
<p lang="fr">Ceci est du texte</p>
</body>
</html>
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:
You can't have two <html>
tags in the same document. You should use one <html>
tag without the lang
attribute and use the lang
attribute on tags that contain only one language. Here is an example:
<html>
<head>
<!--some elements in the head-->
</head>
<body>
<p lang="en">This is text</p>
<p lang="fr">Ceci est du texte</p>
</body>
</html>
© 2022 - 2024 — McMap. All rights reserved.