Recommended Meta Elements?

2019-04-24 14:14发布

问题:

Setting up a "basic framework" for my website projects, I'm wondering which meta elements are really necessary/recommended? In particular, I'd like to know how to deal with the language attribute(s)!? In the following example, I think sth. is repeated unnecessarily...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">

<head>

<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="content-style-type" content="text/css" />
<meta http-equiv="content-script-type" content="text/javascript" />
<meta http-equiv="content-language" content="en" />
<meta http-equiv="language" content="en" />

<title> Title </title>
<base href="http://www.mydomain.com" />

<meta name="charset" content="utf-8" />
<meta name="content-language" content="en" />
<meta name="language" content="en" />

<meta name="description" content="description" />
<meta name="keywords" content="keywords" />

</head>

P.S. "content-language" = "language"?

回答1:

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

Definitely recommended

<meta http-equiv="content-style-type" content="text/css" />

Useless, browsers only support CSS.

<meta http-equiv="content-script-type" content="text/javascript" />

Useless, browsers only support JavaScript.

<meta http-equiv="content-language" content="en" />

Redundant to <html lang="en">

<meta http-equiv="language" content="en" />

Doesn't exist, AFAIK.

<title> Title </title>

Definitely recommended.

<base href="http://www.mydomain.com" />

Depends on how you want your relative links to work, I suppose.

<meta name="charset" content="utf-8" />
<meta name="content-language" content="en" />
<meta name="language" content="en" />

Look like typo's.

<meta name="description" content="description" />

Probably useful.

<meta name="keywords" content="keywords" />

Ignored by every search engine due to widespread abuse.



回答2:

Use this for HTML 5:

<!DOCTYPE html>

This looks wrong:

<meta name="charset" content="utf-8" />

should probably be this for HTML 5:

<meta charset="utf-8">

That is the new HTML 5-way of setting charset encoding. It is highly recommended to also include the old way:

<meta http-equiv="content-type" content="text/html; charset=utf-8"/>

These should be directly after the opening head-tag:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
        <title>The title</title>
    </head>
    <body>
    </body>
</html>