Switching languages and 'lang' attr in html tag

hi,

I have a website in which I switch languages… the default lang is Spanish… user can switch to English…

now here

it says:

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.

(emphasis mine)

does this mean I need to change the ‘lang’ attr for the <html> tag every time the user switches languages?

thank you…

If the content of the page is English then the lang attribute should be ‘en’, if the content is Spanish then it should be ‘es’. If both languages are in the same page then there should be multiple lang attributes so that each piece of content in a given language is appropriately identified. The attribute can go on ANY tag in the page so as to identify that the content of that tag is in a different language. The nearest lang attribute to the content should be the correct language for that content.

1 Like

ok… thank you for your help… I was just wondering if the ‘lang’ attr in html tag is just for the default language or for the currently-appllied language also…
(I didn’t know, though, you could also apply this ‘lang’ attr to other tags as well…:wink:
(but if I have set ‘lang’ attr in html tag I don’t need to set it for other tags, right? because when I switch languages it switches for the entire site…)

thanks again…

actually, what is the purpose of this ‘lang’ attribute? why does HTML (or the server or whatever) need to know what language a site is in?

thank you…

Perhaps this article will help to explain…

1 Like

great… thank you…

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.