代码之家  ›  专栏  ›  技术社区  ›  PeanutsMonkey

HTML 5的建议元标记应该被视为必须具有

  •  37
  • PeanutsMonkey  · 技术社区  · 13 年前

    我正在考虑将用XHTML 1.0编写的页面迁移到HTML 5,并考虑在包含 meta 中的标记 <head> 要素例如,我当前的页面符合XHTML 1.0,它包含以下内容 标记

    <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
    <meta http-equiv="content-language" content="en-us" />
    <meta http-equiv="cache-control" content="no-cache" />
    <meta http-equiv="pragma" content="no-cache" />
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <meta name="author" content="" />
    <meta name="copyright" content="&copy; 2012" />
    <meta name="robot" content="noindex, nofollow" />
    

    以下内容对于HTML5是否足够?我是否也可以包括它们?

    我的理解是 要素 <meta http-equiv="content-language" content="en-us" /> 现在可以全局应用于 <html> 要素

    <html lang="en-us">
    <head>
    <meta charset="UTF-8" />
    <meta http-equiv="cache-control" content="no-cache" />
    <meta http-equiv="pragma" content="no-cache" />
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <meta name="author" content="" />
    <meta name="copyright" content="&copy;" />
    <meta name="robot" content="noindex, nofollow" />
    <title>sample code</title>
    </head>
    </html>
    
    3 回复  |  直到 11 年前
        1
  •  26
  •   Torsten Walter    13 年前

    没有所谓的最小元标签(当然,除非我误解了你的问题)。据我所知,不需要元标签,您添加的标签是满足您特定需求的标签。

    请考虑以下文件:

    <!DOCTYPE HTML>
    <html>
        <head>
            <title>Some Title</title>
        </head>
        <body>
    
        </body>
    </html>
    

    您可以验证它,而不会收到任何警告。验证器只是提醒您缺少默认编码。这甚至不是一个警告,只是一个信息。

    这个 working draft 关于元标签有这样的说法:

    meta元素表示无法使用title、base、link、style和script元素表达的各种元数据。

    它继续说:

    4.2.5.1标准元数据名称

    应用程序名称、作者、描述、生成器、关键字

    此外,它还提到了一些关于页面状态、上下文表示和字符编码的附加标签。

    尽管这些ar都不是标准明确要求的,但实际上有一些最佳实践,尤其是关于搜索引擎优化(SEO)。这与HTML标准无关,而是与web(搜索)爬网程序有关。

    你可以在 Webmaster Tools meta tag support page

        2
  •  7
  •   Loïc Faure-Lacroix    12 年前

    根据 http://validator.w3.org/ 以下是一个非常简单的有效HTML5文档示例,实际上其他所有内容都是可选的。

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="UTF-8">
        <title>Valid HTML5 Document!</title>
    </head>
    </html>
    

    因此,您绝对必须定义字符集元标记,其他一切都是为了实现您的目标(搜索引擎相关的东西、缓存控制等)。

        3
  •  6
  •   Jukka K. Korpela    13 年前

    meta 标签是任何HTML5草案所必需的。(HTML5正在进行中,可能随时更改,恕不另行通知。)

    您列出的许多标签,包括带有 content-language ,甚至不允许(符合)根据HTML5草案。在实践中,它们中的大多数是无用的,但也有一些是有害的(比如排除机器人的那一种,在大多数情况下,还有那些试图阻止所有缓存的)。

    您的后一段代码无效: html 元素必须包含所有其他元素,并且 head 元素必须包含 title 元素(在所有HTML版本中)。

    查阅最新信息 W3C HTML5 起草并使用实验检查器 http://validator.nu