SKero2004
SKero2004

Reputation: 143

What is <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />?

When I create a new Html file in Visual Studio 2017, this:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta charset="utf-8" />

always shows up in the <head>.

The program works just fine without it. So, can someone please tell me what it does?

Upvotes: 6

Views: 45783

Answers (3)

brk
brk

Reputation: 50346

meta which is basically metadata is a HTML tag which provides the information about the data.

The meta data is always passed as a name-value pair.

For example in http-equiv="Content-Type", http-equiv is the key name and "Content-Type" is the value, same with charset="utf-8".

This meta information

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

specifies the media type which is text/html and the character set.

In HTML5, both <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> and <meta charset="utf-8" /> are the same. The latter is the just a short version. Since different languages have different character sets, charset=utf-8" can be important in ensuring the page displays correctly across browsers.

Upvotes: 1

Inus Saha
Inus Saha

Reputation: 1918

According to HTML Dog:

The charset attribute can be used as a shorthand method to define an HTML document's character set, which is always a good thing to do. <meta charset="utf-8"> is the same as <meta http-equiv="content-type" content="text/html; charset=utf-8">.

So it's basically used to define the charset of your HTML document.

The reason why Visual Studio 2017 adds both the meta tags may be because this way your HTML will be maximum compatible with older browsers.

<meta http-equiv="content-type" content="text/html; charset=utf-8"> is the old way to define the charset.

<meta charset="utf-8"> is the new and shorter way to do the same thing.

Upvotes: 7

robertgrzonka
robertgrzonka

Reputation: 192

UTF-8

Wikipedia says:

UTF-8 is a variable width character encoding capable of encoding all 1,112,064 valid code points in Unicode using one to four 8-bit bytes.

Shorthand: UTF-8 is world-wide dominant and default encoding. It contains all of the specific letters (e.g. polish ąęóżź), signs (#$%›ř£ŕ‹řŗŠ’ģýņ etc) or emojis (💎🦄✨).

meta http-equiv

W3Schools says:

The http-equiv attribute provides an HTTP header for the information/value of the content attribute.

content-type specifies the character encoding for the document.

Shorthand: Thanks to <meta http-equiv="Content-Type" content="text/html"> browsers know how to read your page and how to parse it and show it to the user.

Upvotes: 2

Related Questions