What happens if the meta tags are present in the document body?
Asked Answered
E

9

72

I am working on a ASP application and the code, template and files are organized in a way that does not allow me to alter anything outside the body tag. So I am thinking about inserting the meta tags inside the body -- like this:

<!-- FEW ASP INCLUDES -->
<html>
    <head>
    <!-- FALLBACK TITLE AND DESCRIPTION -->
    <title>Default Title</title>
    <meta name="description" content="Default Description">
</head>
<body>
    <!-- SOME HTML MARKUP -->
    <div class="dynamic-content">
        <!-- InstanceBeginEditable name="dynamic-content" -->
        <!-- THIS IS WHERE I CAN WRITE ASP CODE -->
        <title><%= Page.Meta.GetTitle( yada, yada ) %></title>
        <meta name="description" content="<%= Page.Meta.GetDescription( yada, yada ) %>">
        <!-- InstanceEndEditable -->
    </div>
    <!-- SOME MORE HTML MARKUP -->
</body>
</html>

I am wondering how good it is to put meta tags inside the body of an HTML document. How does it affect:

  1. search engines
  2. browsers
Earhart answered 19/9, 2009 at 5:26 Comment(0)
F
54

This is of course invalid as per HTML4.01. META tags are only allowed within HEAD (just like, say, TITLE) so by putting it into a BODY, you're essentially creating an invalid markup.

From the cursory tests, it seems that some browsers (e.g. Firefox 3.5 and Safari 4) actually put these elements into HEAD when creating a document tree. This is not very surprising: browsers are known to tolerate and try to interpret all kinds of broken markup.

Having invalid markup is rarely a good idea. Non-standard handling by browsers might lead to various hard-to-pin rendering (and behavioral) inconsistencies. Instead of relying on browser guessing, it's best to follow a standard.

I don't know how search engines react to such tag soup, but I wouldn't risk experimenting to find out :) Perhaps they only parse HEAD tag for certain information and will skip your BODY-contained tags altogether. Or maybe they consider these to be some malicious gambling attempts and black-list pages containing such markup. Who knows.

The bottom line — avoid this whenever possible.

Froebel answered 19/9, 2009 at 6:11 Comment(4)
Sigh, I'll have re-arrange all code. Any suggestions that help make this process less painful will be appreciated.Earhart
If you're using HTML5 it is allowed to use <meta> tags inside a <body> tag as long as there is an itemprop attribute present. See the spec.Remarkable
Can't find it in the spec but w3.org validator also allows meta tags with property (rdfa-lite) attributes when using html5Acheron
The Bing Webmasters SEO site scan tool does not highlight a meta tag in the body as an issue. It reads it well and understands the content.Cruickshank
F
34

The bottom line is to avoid this whenever possible when the DOCTYPE forbids it. I think this is definitely permitted in HTML5 and very useful in cases using microdata. Example: http://schema.org/Event

Fluidize answered 4/10, 2011 at 8:36 Comment(3)
W3S states that <meta> must always be in the <head>: w3schools.com/tags/tag_meta.asp but I don't see that being true in the HTML5 spec: w3.org/TR/html5/document-metadata.html#the-meta-element . Nevertheless I use them for exactly the same reason: to add metadata (to blog posts). Seems to validate happily enough.Cilia
...though I've just realised I'm forced to use XHTML, so I don't really know. I definitely prefer plain HTML5!Cilia
If HTML5 allows tag x within tag y, then XHTML5 allows tag x within tag y too. The big difference is that XHTML5 must be valid XML (i.e. no unclosed tags), making it easier to parse than HTML.Sweetener
S
11

If your aim is search engine optimization, then it is probably a good idea to follow the standards and put all your meta tags in the <head>. However, as far as browser behavior goes, if you place <meta> tags into your <body> they will still function. I decided to test this using multiple <meta http-equiv="refresh"/> tags and <title> tags in an otherwise standards-compliant document.

The results of my tests:

Firefox 18, Firefox 3.6, Firefox Mobile, Chrome 24, Chrome for Mobile, Opera 12, IE6, IE8, IE10:

  • All <meta> tags in the body were processed.
  • The first <title> tag in the document was processed, even if it was in the body. Subsequent <title> tags were ignored.
  • The earliest meta refresh directive took effect, implying that both were processed.

IE9:

  • Same as above, except all <title> tags in the body were ignored.
  • IE10 in IE9 Standards mode also behaves like this.
  • IE9 in IE8 Standards mode behaved the same as IE8, allowing 1 <title> tag in the body.

So, what happens when you use meta tags in the body? By and large, they seem to work fine. The meta tags will probably be processed, so if you can't put them in the head then I wouldn't fret too much.

Soffit answered 24/1, 2013 at 17:1 Comment(1)
Please note you have to surround HTML code bits with backticks ` to get them to display literally.Manet
D
6

I wouldn't do it. That's not where those tags go, and the search engines might view it as spamming. If you can reorganize the master page you can always add a contentplaceholder up in the head section. I've done it trivially with:

<asp:ContentPlaceHolder ID="HeadTags" runat="server" />

This way you can add whatever content you like in the head section back on your page:

<asp:Content ID="Whatever" ContentPlaceHolderID="HeadTags" runat="server" >

    <meta ... >

</asp:Content>
Doodlebug answered 19/9, 2009 at 6:3 Comment(3)
Not a Classic ASP solution thoughRosner
No, probably not. But as crappy answers go it not only works in production, it has four votes.Doodlebug
Classical ASP solution... that's the essence of the question!Earhart
R
6

meta tags can be added anywhere in the HTML.

The web crawlers can read them but the only issue is when you have to share your pages over some application like facebook messenger, whatsapp etc.

These applications only read meta tags present inside the head tag. So, the og:image, og:description properties of meta tag if placed inside body tag are not read and hence won't be displayed while sharing in such applications.

If its only for SEO purpose, you can add meta tag anywhere but it is recommended to add inside head tag only

Rozina answered 18/1, 2019 at 5:32 Comment(0)
D
4

Some meta tags that are meant for search engines will not be honored by the search engines in the body section of the page.

For example Google says that it will not honor a rel=canonical in the body of the page, but only in the head of the page. Here is what Matt Cutts from Google says:

We don’t allow rel=canonical in the BODY (because as I mentioned, people would spam that),

Differ answered 19/3, 2013 at 23:56 Comment(0)
C
3

I would say you to use it. I found meta tags inside body on various webpages, and they are on one of top 10 searches (on google). It shows, at least to me, that searh engines don't mind if you have used this approach.

You must go ahead if there's no other way around.

Counteract answered 5/1, 2013 at 10:29 Comment(0)
P
0

I have put some meta tags into the body, but that is because of the Microdata technology. When I do not have a regular element with the info, that I need to describe the object according to the schema.org vocabulary , I set a meta tag with this content. I prefer to do it that way instead, to set an element with display:none. The way with display:none may cause more google problems instead of this, as far as I know. I agree it is not the best practice, but when I validate my document (HTML5) I pass the validation with zero errors. Also I have done this trick for a several projects and none of them has problems with google or other search engine. Even microdata improve the search engine ranking. I don't know what exactly you want to do with this meta tags into the body, because I have not saw any microdata in your code. If you need it for this approach I think it is ok, but in other cases meta elements must be in head section!

Prau answered 21/6, 2013 at 9:44 Comment(0)
C
0

Having the META Description tag in the websites is invalid markup, however is not a huge issue as search engines can regularly find the tag where ever it is. My website does this, have a look at my HTML

http://cameras.specced.co.uk/compare/268/Canon_EOS_200D

The META is in the website BODY however it has been indexed by google and the page meta description has been set as the click though text in google search results.

Coughlin answered 22/7, 2017 at 13:3 Comment(1)
Link no longer workingGirdle

© 2022 - 2024 — McMap. All rights reserved.