What a canonical tag does and why you need one

A canonical tag is a single line of HTML code that tells search engines which version of a page is the "official" one when the same content appears at multiple web addresses. Search engines like Google crawl the web constantly, and without a canonical tag, they may index duplicate versions of your page separately — which can split your search ranking across those versions instead of concentrating it on one.

The canonical tag lives in the <head> section of your HTML document and points to the URL you want search engines to treat as the primary version. This matters most when you have the same content accessible through different URLs: a page with and without "www", with and without a trailing slash, or the same product listed under multiple category paths.

Without a canonical tag, search engines have to guess which version matters. With one, you control that decision and keep your search visibility focused.

Key Takeaways

  • A canonical tag is a single line of code placed in the <head> section that points search engines to the primary version of a page.
  • The tag looks like this: <link rel="canonical" href="https://example.com/page"> and must use the full URL including the protocol (http or https).
  • Use a canonical tag whenever the same content is accessible from multiple URLs, such as with or without "www" or with different tracking parameters.
  • The URL in the canonical tag should always be absolute (the complete web address), never relative, and should match exactly how you want that page indexed.

Where to place the canonical tag in your HTML

The canonical tag belongs in the <head> section of your HTML document, between the opening <head> tag and the closing </head> tag. This is the same section where you place your title tag, meta descriptions, and links to stylesheets.

Open your HTML file in a text editor and locate the <head> section. If you are working with a website builder or content management system like WordPress, you may not see the raw HTML — instead, you will find a field labeled "Canonical URL" or "Canonical Link" in the page settings or SEO plugin.

Here is what the placement looks like in a complete HTML document:

<!DOCTYPE html> <html> <head>   <title>My Page Title</title>   <meta name="description" content="Page description">   <link rel="canonical" href="https://example.com/my-page"> </head> <body>   <!-- Page content goes here --> </body> </html>

The canonical tag can go anywhere within the <head> section. Many developers place it near the top, after the title tag, but the exact position does not affect how search engines read it.

The correct syntax for a canonical tag

The canonical tag has a specific format that search engines expect. Any deviation — a missing quote, a typo in the URL, or a relative path instead of a full URL — can cause the tag to be ignored.

The correct syntax is:

<link rel="canonical" href="https://example.com/page">

Break this down: link is the HTML element, rel="canonical" tells the browser this is a canonical reference, and href="https://example.com/page" contains the full URL of the primary page. Always use the complete web address, starting with https:// or http://, and include the exact path and filename.

Common mistakes that break the tag include using a relative URL like href="/page" instead of the full address, forgetting the closing >, or mistyping rel="canonical" as something else. Search engines will simply skip a malformed tag and treat all versions as separate pages.

When to use a canonical tag on your site

You need a canonical tag whenever the same content is reachable through more than one URL. This happens more often than you might think, especially on larger sites or e-commerce platforms.

Common situations where a canonical tag helps include pages accessible with and without "www" (example.com versus www.example.com), pages with and without a trailing slash (example.com/page versus example.com/page/), product pages listed under multiple categories, pages with tracking parameters in the URL, and printer-friendly or mobile versions of the same content.

If every page on your site has only one URL and no duplicate content exists elsewhere, you may not need canonical tags. However, adding them does no harm and is considered a best practice on any site larger than a few pages.

How to test if your canonical tag is working

After you add a canonical tag, verify that search engines can read it correctly. The easiest method is to use Google Search Console, which is free and shows you how Google sees your pages.

Log into Google Search Console with your Google account, select your website property, and navigate to the "Pages" section under "Indexing". Find the page where you added the canonical tag and click it. Google will show you the canonical URL it detected — if it matches the URL you specified in your tag, the tag is working.

You can also view the page source directly in your browser: right-click on the page, select "View Page Source" (or "Inspect" in most modern browsers), and search for "canonical" using Ctrl+F (Windows) or Cmd+F (Mac). The canonical tag should appear in the <head> section with the correct URL.

If Google Search Console shows a different canonical URL than the one you added, or if you cannot find the tag in the page source, double-check your HTML syntax and make sure the file was saved and uploaded to your web server.

Canonical tags on WordPress and other platforms

If you use WordPress, you do not need to edit HTML directly. WordPress includes a canonical tag automatically on every page, pointing to that page's own URL. If you want to change which URL is canonical, most SEO plugins like Yoast SEO or Rank Math provide a field in the page editor where you can enter a different canonical URL.

Open the page you want to edit, scroll to the SEO plugin section (usually below the editor), and look for a field labeled "Canonical URL" or "Canonical Link". Enter the full URL you want to be canonical and save the page. The plugin will add the tag to the <head> section for you.

Other platforms like Shopify, Wix, and Squarespace also handle canonical tags automatically and provide settings to override them if needed. Check your platform's documentation or SEO settings to find where to manage canonical URLs — you should not need to touch the HTML code directly.

Frequently Asked Questions

Can I use a canonical tag to point to another website's page?

Yes, you can point a canonical tag to a URL on a completely different domain. This is useful if you have syndicated content — for example, if your article appears on both your site and a news aggregator, you can use a canonical tag on the aggregator's version to point back to your original article. Search engines will treat your version as the primary one.

What happens if I add a canonical tag pointing to the wrong URL?

Search engines will index the URL in the canonical tag instead of the page you are on. If you point to the wrong page by mistake, search engines may stop indexing the current page entirely. Always double-check the URL in your canonical tag before publishing, and use Google Search Console to verify that the tag points where you intended.

Do I need a canonical tag on every page of my site?

It is not required, but it is considered best practice. Adding a self-referential canonical tag (a tag that points to the page's own URL) on every page does no harm and makes your site's structure clearer to search engines. Many developers add them automatically as part of their template.

Can I use multiple canonical tags on one page?

No. If you add more than one canonical tag to the same page, search engines may ignore them or become confused about which URL is canonical. Use only one canonical tag per page, and make sure it points to a single, definitive URL.

Does a canonical tag prevent duplicate content penalties?

A canonical tag tells search engines which version to index, but it does not prevent Google from seeing the duplicate content. If you have sensitive or private content that should not be indexed at all, use a robots.txt file or a noindex meta tag instead of a canonical tag.