Technical SEO

How to Add a Canonical Tag and Check That It Points to the Right URL

Add a canonical tag, check its URL in source and rendered HTML, and compare your choice with Google’s in Search Console.

Editorial illustration for How to Add a Canonical Tag and Check That It Points to the Right URL

A canonical tag names the URL you prefer when similar or duplicate content is available at more than one address. The implementation check is fairly direct: does the page output contain one canonical link, in a valid HTML <head>, with the intended absolute URL? Whether Google selects that URL is a separate question.

Choose the preferred URL

Suppose a product is available at both https://www.example.com/products/green-dress/ and https://www.example.com/products/green-dress/?utm_source=newsletter. The clean URL is the intended preferred version. A canonical link on the parameter URL can point to it; a canonical on the clean page can point to itself. This is a preference, not an instruction that guarantees Google will select the URL. Google’s canonicalization guidance describes the markup, while the distinction between redirects and canonical hints is also explained in this canonical-tag guide.

First make sure these really are alternate URLs for substantially the same content. A canonical is not a way to make two meaningfully different pages interchangeable.

Add the link in the HTML head

On the clean product page, use a self-referencing canonical:

<!doctype html>
<html lang="en">
<head>
  <title>Green dress</title>
  <link rel="canonical" href="https://www.example.com/products/green-dress/">
</head>
<body>
  <h1>Green dress</h1>
</body>
</html>

On the tracking-parameter variant, put the same preferred URL in that page’s head:

<!doctype html>
<html lang="en">
<head>
  <title>Green dress</title>
  <link rel="canonical" href="https://www.example.com/products/green-dress/">
</head>
<body>
  <h1>Green dress</h1>
</body>
</html>

The second example is the HTML served for the ?utm_source=newsletter URL; the parameter belongs to the requested address, not to the preferred URL in href. Use a full URL including scheme and host. Google recommends absolute rather than relative canonical URLs and accepts this link element only in the HTML head. Check that a template, CMS setting, or plugin has not added another canonical: one page should declare one choice. See Google’s markup requirements and the single-tag implementation advice.

Check what the page actually outputs

Request each URL and inspect its initial HTML response, rather than assuming the template you edited is what visitors receive. Find rel="canonical" inside the <head>, count the canonical links, and compare the href character for character with https://www.example.com/products/green-dress/. Check both the clean and parameter URLs: the two example pages have different addresses but intentionally declare the same preferred URL.

For a JavaScript-rendered page, compare that initial HTML with the rendered page. The preferred setup is to provide the canonical in source HTML and leave it unchanged when JavaScript runs. If you cannot put it in source HTML, Google advises leaving it out there and setting it only with JavaScript—not declaring one URL in source and replacing it with another during rendering. If a tag is missing or changes unexpectedly, investigate the page output or rendering before treating the issue as a Google canonical-selection problem. Google explains the JavaScript guidance here.

A matching source and rendered tag establishes output consistency. It does not establish that the preferred URL has been indexed.

Check the target, then compare Google’s choice

Follow the URL in href. Confirm that it is the version you intended and check whether that target is crawlable and indexable. Also look for a contradictory URL choice elsewhere in the page’s output or URL behavior—for example, a redirect toward one address paired with a canonical toward another. These checks matter even when the link element itself is perfectly formed. The target-check advice and redirect-conflict example provide useful starting points.

Finally, inspect the page URL in Google Search Console’s URL Inspection tool and compare its user-declared canonical with its Google-selected canonical, as described in this Search Console workflow. If the declared URL is wrong, return to the page output. If the declaration is right and Google reports the same selection, you have agreement on the reported canonical—not a promise about search appearance or ranking. If Google reports a different selection, investigate the target and other URL signals; that difference alone does not prove the HTML tag was implemented incorrectly.

Find a note

Search by topic, title, or keyword.