Doesn’t it make more sense to have the lang tags as the first one in the head tags? Wouldn’t this align better with how the head is meant for metadata information
lang
is a global attribute, meaning you can set it on any element.
By default, it’s empty or inherits the lang
value from its parent.
When you set it on the base html tag, it applies to all children in the body and head.
If it were only set on the head tag, the children in the body wouldn’t inherit that value.
@Flynt
To expand: your confusion might stem from thinking it’s metadata, but it’s not.
You might want to set lang
explicitly on a section if you’re mixing languages on a page.
Flynt said:
@Flynt
To expand: your confusion might stem from thinking it’s metadata, but it’s not.
You might want to set lang
explicitly on a section if you’re mixing languages on a page.
Thanks, that clears up my confusion. Now it makes sense.
Edit: I’m still learning and the answers to this question have reignited my faith in the relevancy of this field. I also asked some AI chatbots about this and not a single one made any sense.
Because lang isn’t a tag, it’s an attribute that describes the contents within a tag.
You put it inside any tag you wish to describe the language of. For example, if you want a paragraph in French, you can do
Saucisson
.To label a whole HTML file as being in English, is the right place since it wouldn’t logically apply to the contents of only the head.
@Paris
So if you set English for the entire page but had a paragraph in another language, can you add that attribute to that p tag and it would take priority?
Caden said:
@Paris
So if you set English for the entire page but had a paragraph in another language, can you add that attribute to that p tag and it would take priority?
Yes, the screen reader will read it in the correct language if properly set up.
Caden said:
@Paris
So if you set English for the entire page but had a paragraph in another language, can you add that attribute to that p tag and it would take priority?
You can also do this with palavras dentro do parágrafo.
@Paris
Thanks, that makes sense now. I really wasn’t aware that each element could have a different lang tag. Looking back, I should’ve experimented before asking.
I assume you mean the lang attribute that can be used in the html tag (to denote the language of the entire page) and anywhere inside the body element to denote sections where something might be in a different language than the rest of the page?
lang attribute.
If Block 1 is in English, and Block 2 is in French, how would one specify this at the head level?
The lang attribute can be different for various elements, so it isn’t guaranteed to be document-wide metadata.
It’s primarily focused on assistive technology, so having it on the html element allows the body to inherit it using normal nesting rules.
Honestly, it may have just been a 50-50 decision when it was added.
Did you mix up attribute and tag? When you place the lang attribute on HTML, you’re also indicating that the language is used inside metadata (like and ), as well as the title. After setting the main language for the entire document, you can override it on specific elements that have content in a different language.
Because the lang attribute is meant to signal specific languages in the body. A page can contain multiple languages.
I feel like someone who doesn’t know the difference between an attribute and a tag shouldn’t criticize its placement. But that’s just my opinion.