which is the correct way to declare charset in HTML page?
What is the difference between these meta tags in HTML
<meta name="http-equiv" content="Content-type: text/html; charset=UTF-8"/>
<meta http-equiv="Content-Type开发者_高级运维" content="text/html; charset=utf-8" />
in w3c validation first one is not recognized but for some reason I have to use that.
My guess is that the http-equiv
attribute allows to specify information that would normally be provided via HTTP headers (and user agents can opt to handle it as such) while using name
is a syntax to set free-form arbitrary key/value pairs with additional information about the document (author, keywords...)
Here's the spec for HTML 4:
name = name [CS] This attribute identifies a property name. This specification does not list legal values for this attribute.
http-equiv = name [CI] This attribute may be used in place of the name attribute. HTTP servers use this attribute to gather information for HTTP response message headers.
Your first example is possibly legal but it won't render any appreciable result.
I've never seen the first one before.
Here's the simplest:
<meta charset="utf-8">
If you're using XHTML, you can also declare the charset in the XML prologue:
<?xml version="1.0" encoding="UTF-8"?>
By the way, the first one is new for HTML5, but a lot of work has been done to demonstrate that it works on all known extant browsers, so it's safe to use, even with an older DOCTYPE.
精彩评论