George
George

Reputation: 124

Setting two charsets? utf-8 and text/html

I'm new to learning HTML and learning about metadata in a webpage. It seems like people prefer you have to set the character set to support utf-8 and people are also saying have charset="text/html" so browsers know what kind of information they are receiving. How can I set both since it seems like both use the same attribute?

Upvotes: 0

Views: 86

Answers (1)

Ry-
Ry-

Reputation: 224857

text/html is a media type, not a character set. The server can send a Content-Type: text/html; charset=utf-8 header to identify the content as HTML encoded as UTF-8. When you’re using a <meta> tag, though, the content is already known to be HTML and the only thing that matters is the charset, so HTML5 introduced the option to write <meta charset="utf-8"> as shorthand for <meta http-equiv="Content-Type" content="text/html; charset=utf-8">. (Older browsers also support this because people had a habit of forgetting quotes in the original.)

In short, if you’re using a <meta> tag, just write this:

<meta charset="utf-8">

and you’re done. The page is already HTML.

Upvotes: 1

Related Questions