Mobile app version of vmapp.org
Login or Join
Kevin317

: Can I use tags in the body of an HTML document? 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.

@Kevin317

Posted in: #Html #Html5 #Microdata #Seo

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?

10.03% popularity Vote Up Vote Down


Login to follow query

More posts by @Kevin317

3 Comments

Sorted by latest first Latest Oldest Best

 

@Martha676

The link element can be added to the body of an HTML document if the itemprop attribute is present. Here's a demo.

Also here's a link itemprop attribute example.

10% popularity Vote Up Vote Down


 

@Ann8826881

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 (e.g., <link href="" rel="" />) in the body, but only those with an itemprop attribute (for Microdata) resp. a property attribute (for RDFa).

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>

10% popularity Vote Up Vote Down


 

@Nimeshi995

W3Schools does not set the industry standards on HTML coding. They are simply a 3rd party reference site that is not affiliated with the W3C in anyway. W3Schools and other sites are often wrong when using cutting edge coding technologies such as Schema and Responsive design. When using fairly new code your one stop shop should be W3C as set the compliance standards, and maybe HTML5 Doctor if you need help understanding HTML5 through they are not official but highly respected.

Looking at your code it passes W3C validation without any issues with the link element contained within the <body> </body>

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<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>
</body>
</html>


SHORT ANSWER: Yes, you can use <LINK> within <body> </body> but as Unor has mentioned in his answer must include itemprop.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme