Arad olfati
Arad olfati

Reputation: 3

Why we use lang attribute as html atrribute when meta tags tell more information about dcument?

We use meta tags to tell more information about a document. For example the lang attribute on HTML tag, provides more information about the document. Why we don't use it as meta tag attribute?

Why do we use in HTML tag?

Upvotes: 0

Views: 895

Answers (2)

Tushar Shahi
Tushar Shahi

Reputation: 20441

There used to a meta tag to indicate language.

<meta http-equiv="Content-Language" content="en-US">

http-equiv attribute is set to provide information equivalent to what can be given by a similarly-named HTTP header.

The header it tries to mock is Content-Language: de, en. It is to describe the language(s) intended for the audience.

From the docs:

If "Content-Language: de-DE" is set, it says that the document is intended for German language speakers (however, it doesn't indicate the document is written in German. For example, it might be written in English as part of a language course for German speakers. If you want to indicate which language the document is written in, use the lang attribute instead).

So even before it was deprecated it had a different purpose.

lang attribute is used to define the language of the element. It does not indicate any intended audience, and is more about what is the content inside the tag. It can be put on <p>,<li> etc. Elements might be having content in a different language. You can have different divs in your web page having different languages. Defining one lang attribute in helps propagate it to all children, unless overridden.

Upvotes: 1

Avadh Kanaiya
Avadh Kanaiya

Reputation: 1

This use of the content-language value for an http-equiv attribute is deprecated by the HTML specification, and should no longer be used. Instead, you should always use a lang attribute on the html tag to declare the default language of the text in the page.

Upvotes: 0

Related Questions