5

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?

SKero2004
  • 133
  • 1
  • 2
  • 15
  • Related question: https://stackoverflow.com/questions/4696499/meta-charset-utf-8-vs-meta-http-equiv-content-type – jkdev Jul 02 '19 at 01:22

3 Answers3

7

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.

Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
Inus Saha
  • 1,918
  • 11
  • 17
  • Please link to the website that contains the quote. See https://stackoverflow.com/help/referencing – BoltClock Jun 24 '18 at 03:27
  • @BoltClock Thank you for your suggestion. i have added the link to the page. "i am still learning on Stack Overflow" – Inus Saha Jun 24 '18 at 03:33
  • It's confusing way to define, if you take into account that most meta attributes are of the form ``. Would have been better to introduce a meta tag like this: `` – Sebi2020 Oct 12 '21 at 13:19
2

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.

Community
  • 1
  • 1
1

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.

Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
brk
  • 48,835
  • 10
  • 56
  • 78