Reputation: 23780
You can send the charset both in the http response headers and also you can define a charset in the html file you have sent..
What happens if these 2 are different charsets? How does the browser use the charset for what it received in the http headers and where does it matter what charset it provided in the html file itself?
Upvotes: 5
Views: 1516
Reputation: 201568
The HTML 4.01 specification clearly says, in 5.2.2 Specifying the character encoding, that information in an HTTP header has precedence over a meta
tag. HTML5 PR does not change this, but it adds, reflecting browser practice, in 8.2.2.2 Determining the character encoding that both of them are overridden by a Byte Order Mark (BOM) at the start of the HTML document (so if you have saved your .html file with “Save as UTF-8 with BOM”, it will be treated as UTF-8 no matter what).
A meta
tag that specifies character encoding takes effect if the information is not provided in an HTTP header or with a BOM. A server might not include charset
parameter in the Content-Type
header, or the HTML document might be opened locally so that there are no HTTP headers at all. When a user saves an HTML document in his own device, the HTTP headers are not saved. This is the main reason for using a meta
tag to specify character encoding; but it should then specify the correct encoding of course.
Upvotes: 4