Mobile app version of vmapp.org
Login or Join
Sent6035632

: HTML (4.01) "lang" attribute: Best practice / Browser compat for where to place: HTML or BODY? I'm just creating a new site from scratch. Each page in that site will have a default language

@Sent6035632

Posted in: #Html #LangAttribute

I'm just creating a new site from scratch. Each page in that site will have a default language and I'd like the markup to reflect it because there will be multiple languages.

I'm using HTML 4.01 and I'm targetting older browsers as well (e.g. IE 6, Opera 8, Lynx etc.). Regarding cross-browser compatibility as well as of "best practices" where to place the lang attribute: To the HTML tag or to the BODY tag or does this make no difference at all?

I'm going towards the BODY tag as it contains all the default languages text, while the HEAD might not always. But I have no clue if any browser is taking care of the lang attribute anyway. Any hints?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Sent6035632

1 Comments

Sorted by latest first Latest Oldest Best

 

@Sims2060225

There isn't any cross-browser compatibility issues AFAIK. But it makes the most sense and is most commonly used by putting it in html since your document isn't just limited to body. See this page for the purpose of lang and this page for the proper use of lang versus other ways of specifying language.

Since lang only specifies the language of the current element and its child elements, unless you place it in your root element (html), you're neglecting a large part of your document (what language is your title, meta description, etc.?). You can, however, add additional lang attributes in other elements further down your document tree if they are in a different language.

More documents outlining best practices:

www.w3.org/International/tutorials/language-decl/ http://www.w3.org/TR/i18n-html-tech-lang/

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme