Reputation: 3841
I am working on internationalizing my website and I am curious as to which spots I should put the lang='$lang'
attribute on. I know for sure I should put it on the html
element but as I was researching more into this I notice some people will put them on form
elements as well.
Is there any benefit of putting it on other elements if you have it on the root html
already? and if so what other elements should I put them on.
Upvotes: 1
Views: 3859
Reputation: 384
W3C says:
Always use a lang
attribute in the html
tag to declare the default language of the page text. When the page has content in another language, add a language attribute to an element that is mounted on that content.
Hope that helps ;)
Upvotes: 2
Reputation: 2321
Always use a language attribute on the html tag to declare the default language of the text in the page. When the page contains content in another language, add a language attribute to an element surrounding that content. Check out this link for more info. https://www.w3.org/International/questions/qa-html-language-declarations
Upvotes: 1
Reputation: 522513
The lang
attribute is "cascading" down to all contained elements. You just need to set it once globally, and all the elements in the page will inherit its value.
The only time you'd set it on nested elements is if those elements are in a different language, e.g.:
<div lang="en">
<h1>"Hello" in different languages:</h1>
<h2>Japanese</h2>
<p lang="ja">こんにちは</p>
<h2>German</h2>
<p lang="de">Hallo</p>
</div>
Upvotes: 5