3 ms·
<body lang="en"> - High? why?
by franze 9y ago
<body lang="en"> - High?
why?
- stephenr 9y agoI'd have thought things like that were better handled as a response header (same for the charset).
- robin_reala 9y agoNo, because pages can be saved, and then the page loses the information. Or rather, by all means do it (it does get the information to the browser quicker) but make sure you also add the information to the page.
- Teichopsia 9y agoI also found that odd. I've always placed mine in the HTML tag. <html lang="en"> tough, I don't know what the difference is.
- robin_reala 9y agoPutting it on <html> is better as that defines the language for <title> as well. The lang attribute defines the language of the tree that the element is the root node of.
- franze 9y agostill, who uses it for what? browsers dont change behaviour because of it, search engines ignore it, users dont see it.
- robin_reala 9y ago1. The main reason is screen readers. Imagine a screen reader trying to pronounce ‘Je ne regrette rien’ with an English voice, then imagine the same with a French voice. 2. I’d be surprised if search engines didn’t use it at least as a flag for content language (although I’m sure that it‘s only supplemental at best). 3. Styling based on language. CSS has a :lang() pseudoclass selector so you can do p:lang(en) { color: red; } p:lang(fr) { color: blue; } . Or tie quote styles to language based on generated content. Or most usefully adjust font metrics based on language for multilingual sites (typically you’d want to boost the font size a little for Chinese or Japanese as there are less characters for same information, but each character is a little more dense).
- ozaark 9y agoActually, browsers do change behavior because of it[1], and users do get affected by it[2]. Google have said last year they ignore the lang tag but they do use the hreflang attribute[3] [1] https://www.w3.org/International/tests/repo/results/the-lang-attribute#basics https://www.w3.org/International/tests/repo/results/the-lang... [2] http://accessibility.psu.edu/foreignlanguages/langtaghtml/#about http://accessibility.psu.edu/foreignlanguages/langtaghtml/#a... [3] https://www.seroundtable.com/google-ignores-the-html-lang-attribute-22974.html https://www.seroundtable.com/google-ignores-the-html-lang-at...
- sjmulder 9y agoI use VoiceOver sometimes which will switch to an appropriate voice for the language.