zer0uno
zer0uno

Reputation: 8030

How does the browser practically detect the HTML page encoding?

Let's suppose that an chracter encoding format called X exists (for example UTF-8), if I insert in the HTML file the tag <meta charset="X"> and then I save the file, obviously, with the same encoding, how can the broswer read the file later?

I mean, how can the broswer know the encoding of an HTML page if, to get encoding, it must read the file? It seems a sort of loop.

Upvotes: 1

Views: 1145

Answers (1)

Cepheus
Cepheus

Reputation: 589

According to https://www.w3.org/TR/html4/charset.html#h-5.2.2, a browser gets the correct encoding from the Content-Type header field of the HTTP response. If this field is not present, the browser reads the HTML page until the META tag, assuming all bytes were ASCII characters. So this only works if ASCII is a subset of the actual encoding.

Upvotes: 1

Related Questions