1

Why html lang="en" is required if we are defining meta charset="utf-8".I mean we have defined charset so what's the use of lang?

What I understand from utf-8 is that it contains characters of almost all language in itself.

1
  • 2
    UTF8 is an encoding, not a language. Language is English, French, Russian, Chinese. All of those arre typically served in UTF8-encoded HTML pages Commented Oct 1, 2020 at 15:31

2 Answers 2

3

The HTML lang attribute is used to identify the language of text content on the web. This information helps search engines return language-specific results, and it is also used by screen readers that switch language profiles to provide the correct accent and pronunciation. I added the article link, you can read more:

Reference

2

You are confusing encoding with language.

Unicode (and the UTF-8 encoding) can represent characters for nearly all languages, you are right, but how to represent them? Fonts need to know the language, in order to display every character in the native form. The same character could be written differently, depending on language (usually it is about ligatures, but also characters could be written differently). Also in old English, sometime we want that the s is written as a f (without the middle line), but we want to write it as s, not using the special character (Unicode has is, for special purpose). But the rules were just for English. Other languages had different rules.

But language defines a lot of other parts: how to write numbers (with decimal dot or decimal comma? How to write dates? etc), but also how to split lines (words).

Then about readers, and if you want that the browser look the definition of a word, or just search engines.

UTF-8 is just an encoding, it should not be confused to the representation of text.

2
  • When I use lang="fr" and run the code(which is in English), it still gives the same output.
    – koil
    Commented Oct 3, 2020 at 9:15
  • @S.Kumar: yeah, sometime it is so, but it doesn't mean it is always the same. Browsers could be more precise (e.g. if needed a larger space after a dot, or not). And JavaScript could use language for formatting, names and numbers. But also widgets. You just tell reader more information about what to expect. It is not a bad things (especially with Indian languages). Not all fonts distinguish language (different glyphs on same unicode codepoint), but also this tell us about quality of font, and attention to details. Commented Oct 3, 2020 at 9:33

Not the answer you're looking for? Browse other questions tagged or ask your own question.