I read lots of information on the web, and couldn't find the answer of this quistion. If I use
<meta charset="utf-8"/>
will the coding be applied correctly in browsers that don't support HTML5?
I understand that HTML5 doesn't require closing the meta tag, but closing it seems more decent to make very old browsers at least try to understand it.
Don't know it this thought is correct, but now I wanted to know if I should include that old
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
format or not (wanting HTML4 compatibility).
Related
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?
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.
My markup has the simple HTML5 compatible <meta> tag like so:
<meta charset="UTF-8">
The document validates well under the HTML5 doctype, but what disadvantages, if any, are there to using this method when it comes to older browsers?
While IE8 and below make up a small percentage of the market share, they do still exist out in the wild, especially in corporate environments. I am finding myself lately producing sites for these corporate environments more and more often and am curious as to what the correct procedure is for backwards compatibility. SEO is generally not a high priority as these are mostly "internal use only" sites that I am working with.
What are the pros and cons of using
<meta charset="UTF-8">
over
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
and vice-versa?
There are no known disadvantages. I just tested with IE 6 (in a virtual XP machine), and it manages <meta charset=utf-8> fine. And you can hardly find an older browser than that in the wild these days.
This is not surprising, since the construct was added to HTML5 after observing how browsers actually parse HTML. This is described in section Extracting character encodings from meta elements in HTML5 CR. The browsers effectively just searches for charset= in the tag and then reads the encoding name after that string. This means that e.g. <meta sdvhnizfb vjkfhifgb ¤¤#%#charset="utf-8"> works, too, though it not particularly recommendable.
The advantages of <meta charset=utf-8> are simplicity, conciseness, and intuitive understandability. And when typing a short string like that, you will seldom make mistakes like you might do with a more complicated string. Just like <!doctype html> is finally a doctype that you can easily memorize, <meta charset=utf-8> can easily be learned and typed. Of course, you should normally use document templates or similar tools, but the point is that you can type those constructs when needed, without consulting a manual.
So what is the best way to define? Thanks!
<meta charset='utf-8'>
or
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
or
<meta http-equiv='charset' content='utf-8'>
The first option, <meta charset='utf-8'>, is preferred, primarily because it's shortest.
Note that the charset declaration should be the first child of the <head>, before any user-controlled content. (in particular, before the <title>)
They are equivalent in HTML5, but I'd recommend using the first form, because it's shorter and easier to remember and was designed for backwards compatibility with older browsers, even in Internet Explorer 6 (see).
The best, and recommended, way is to specify the character encoding (“charset”) both in a Content-Type HTTP header and in a meta tag or, in the case of UTF-8, using a Byte Order Mark at the start. Note that any conflict between the HTTP header and a meta tag is resolved in favor of the HTTP header.
It is much less relevant which of the two forms of meta you use, but the shorter is safer (less opportunities for mistyping or copy error).
References: Specifying the document's character encoding in HTML5 CR and W3C page Character encodings.
The third tag mentioned in the question, <meta http-equiv='charset' content='utf-8'>, is invalid and has no effect. (The W3C validator says: “Bad value charset for attribute http-equiv on element meta.”)
the best way to define the Meta Charset follows:
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
The TAG above is the more complete.
http://www.w3.org/International/O-HTTP-charset.pt-br.php
see my post here
In that context
What is the meaning of value="IE=edge"?
What is the meaning of value="IE=EmulateIE8" ?
IE=edge simply tells IE to use the last version of the rendering engine.
It's documented here, just like the less useful (in my opinion) IE=EmulateIE8.
IE=edge helps you avoiding some "compatibility" behaviors. It makes IE9 more compatible with other modern engines.
See this related question for example. I always start my HTML files with
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
A web application we have for an organisation that is officially upgrading its standard browser from IE6 to IE8 (queue celebrations), we've set all our DOCTYPEs to be <!DOCTYPE html> (as well as fixed other html code) and I thought that in IE8 this would cause the page to be rendered in IE8 Standards Mode. However, it is still shown in IE7 Standards mode.
I've added the <meta http-equiv="X-UA-Compatible" content="IE=8"> into the <head> section and it still fails to default to IE8 Standards mode. I'm presuming at this stage that there must be a setting (perhaps Group Policy etc) that is forcing the mode.
After reading a hack on an MSDN forum that if you put the meta tag before the <html> tag, it correctly displays as IE8 Standards mode, and this worked for me. Is there another way to do this? It just looks terrible seeing the meta tag there...
Here's roughly how each page is made up:
<!DOCTYPE html>
<meta http-equiv="X-UA-Compatible" content="IE=8">
<html lang="en">
<head>
<meta charset="utf-8">
<title>Page Title</title>
</head>
<body>
</body>
</html>
You could set X-UA-Compatible as a HTTP response header, instead of as a meta tag.
This is a much cleaner solution than placing it above the <html> tag.
A confusing useful blog post concerning X-UA-Compatible and its many intricacies:
http://farukat.es/journal/2009/05/245-ie8-and-the-x-ua-compatible-situation
Two possibilities:
The meta tag definitely belongs into the <head> section of the document.
If this is in an Intranet, this may be IE's "Smart default" kicking in. Yes, there is such a thing as smart defaults. See here. Because if you're in an Intranet, IE8 will automatically go into IE7 compatibility mode so as not to break the many corporate apps that rely on IE7. Makes sense, right? Right?