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.