Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meta tags explained: http-equiv and charset

Tags:

html

Which is best? And what is the difference?

<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

or

<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

Another thing, I see that Viewport meta tags and meta http-equiv tags do not get the /> closing tags as charset and other meta tags have...why is that?

Thank you

like image 693
DextrousDave Avatar asked Jul 20 '12 15:07

DextrousDave


People also ask

What is <meta charset> in HTML?

<meta charset>, <meta http-equiv>: a <head> element. If the http-equiv is not an encoding declaration, it can also be inside a <noscript> element, itself inside a <head> element. <meta name>: any element that accepts metadata content.

What is the difference between Meta and http-equiv In HTML?

If the name attribute is set, the <meta> element provides document-level metadata, applying to the whole page. If the http-equiv attribute is set, the <meta> element is a pragma directive, providing information equivalent to what can be given by a similarly-named HTTP header.

What is meta meta tag in HTML?

meta tags live within the head tag of the HTML document. The head tag is used for configurating the HTML file. You use the head tag to add a title to the webpage, link to a CSS stylesheet, and define more information about the HTML document.

What is http-equiv and charset in HTML?

If the http-equiv attribute is set, the <meta> element is a pragma directive, providing information equivalent to what can be given by a similarly-named HTTP header. If the charset attribute is set, the <meta> element is a charset declaration, giving the character encoding in which the document is encoded.


1 Answers

The second one is better, since it's more concise. It was standardized that way in HTML5.

As for the tags ending in />: It makes no difference what tag it is. No tag has to close like that in HTML5. In the olden days of XHTML, all these tags had to close like that, since XHTML is related to XML.

So, the takeaway is thus:

  1. Use an HTML5 doctype: <!DOCTYPE html> - Isn't that just nice and simple?
  2. Definitely use <meta charset="utf-8"> - More concise, more betterererererer...
  3. No need to close your tags with />
like image 170
Joseph Silber Avatar answered Nov 14 '22 23:11

Joseph Silber