koil
koil

Reputation: 49

What is the use of the lang attribute in HTML if we have defined the charset as UTF-8?

Why is html lang="en" required if we are defining meta charset="utf-8"? We have defined a character set, so what's the use of defining a language?

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

Upvotes: 0

Views: 725

Answers (2)

ORHAN ERDAY
ORHAN ERDAY

Reputation: 1076

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

Upvotes: 3

Giacomo Catenazzi
Giacomo Catenazzi

Reputation: 9533

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.

Upvotes: 2

Related Questions