大网数据广告活动
网站运营与故障问答

Can I use <link> tags in the body of an HTML document?

· 52CE 我爱测

Can I use <link> tags in the body of an HTML page? I tried to find the answer to this question, but found contradictory information. When adding Schema.org microdata markup to an HTML page, I want to add canonical info in a link …

问题原文

原帖链接 · Edward Touw · CC BY-SA 3.0

Can I use <link> tags in the body of an HTML page? I tried to find the answer to this question, but found contradictory information.

When adding Schema.org microdata markup to an HTML page, I want to add canonical info in a link tag like this:

<div itemscope itemtype="http://schema.org/Book">
  <span itemprop="name">The Catcher in the Rye</span>—
  <link itemprop="url" href="http://en.wikipedia.org/wiki/The_Catcher_in_the_Rye" />
  by <span itemprop="author">J.D. Salinger</span>
</div>

I got the example code above from Schema.org. According to them, this is the way to go for people that want to add a canonical reference to an itemprop, but don't want to place a hyperlink on their website.

W3 however clearly states that <link> tags should only be placed within the head section, thus making the Schema.org example invalid.

If I want to stick to correct markup, which advice should I follow?

已采纳解答

原帖链接 · unor · CC BY-SA 4.0

Microdata extends HTML5 in a way that link and meta elements can be used in the body, if they contain an itemprop attribute.

If the itemprop attribute is present on link or meta, they are flow content and phrasing content. The link and meta elements may be used where phrasing content is expected if the itemprop attribute is present.

This extension is currently also included in the HTML 5.1 Nightly (Editor’s Draft) (see link element and meta element). But as the Microdata specification became a W3C Note recently, we’ll have to see what happens with this reference.

RDFa 1.1 extends HTML5 in a way that link and meta elements can be used in the body, if they contain a propertỳ attribute.

If the @property RDFa attribute is present on the link or meta elements, they MUST be viewed as conforming if used in the body of the document. More specifically, when link or meta elements contain the RDFa @property attribute and are used in the body of an HTML5 document, they MUST be considered flow content.


So you are not allowed to use any link element in the body, but only those

  • with an itemprop attribute (for Microdata), or
  • with a property attribute (for RDFa), or
  • with a rel value that is defined as "body-ok" (see zgreen’s answer).

Thus your link element can be used in the body:

<body>
<!-- … -->
  <link itemprop="url" href="http://en.wikipedia.org/wiki/The_Catcher_in_the_Rye" />
<!-- … -->
</body>

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2013-11-13)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。