JCalcines
JCalcines

Reputation: 1286

Does the position of the canonical tag matters?

Background: I am working on a JSP web page and the project seems to be pretty fragile. The thing is that there are two tags for generating the canonical tag and I was wondering if this is a mistake of there is a reason behind this. They both are never generated on the same page so there is no competition posible

Depending on the page, the canonical tag can be located at the Position 1 or at the position 2 on the next chunk of code.

<head>
    <meta charset="utf-8">
    <meta name="viewport" ... >
    <link rel="alternate" ... />
    <link rel='stylesheet' ... />
    <link rel='canonical' ... /><!-- Position 1 -->
    <link rel="icon"
    <link rel="manifest" ... />
    <meta name="custom-property"
    <title> My Page </title>
    <link rel='canonical' ... /><!-- Position 2 -->
    <!-- Blah, blah, blah --> 
</head>

Is there any chance that the canonical tag position could affect to the rest of the page?

Upvotes: 0

Views: 226

Answers (1)

Manngo
Manngo

Reputation: 16281

Not entirely sure why you are implementing multiple canonical links, as your example isn’t detailed enough, but here is the general rule:

  • HTML does not — indeed, cannot, specify an order for elements inside the head element. Generally you put elements where you can maintain them best.

Where there are two of the same type of element:

  • for elements that compete, the last one takes precedence
  • for elements that don’t compete, the data is combined; even so, if there is any competition within the data (such as with multiple style sheets), the last data still takes precedence.

Since it is possible that your two canonical elements are in competition, I would be inclined to regard the latter as the canonical canonical element.

Upvotes: 1

Related Questions