Course contentsShow
← Web Development
Lesson 1847 of 2,98234. Metadata and SEOFree lesson

The rel="canonical" Link Element

How to implement canonical tags in HTML using the link element in the document head.

The rel="canonical" Link Element

You'll learn how to add canonical tags to your HTML to tell search engines which version of a page is the authoritative one.

What is the Canonical Link Element?

In the previous lesson, you learned what a canonical URL is—the preferred version of a page when duplicates exist. Now you'll learn how to declare it in your HTML.

The rel="canonical" link element goes in your document's <head> and points search engines to the definitive version of the current page. Think of it like putting a forwarding address on duplicate mail: "This content lives officially at this address."

Basic Implementation

Here's the syntax:

<head>
  <link rel="canonical" href="https://example.com/preferred-page-url">
</head>

The href attribute must contain the absolute, fully-qualified URL of the canonical version—including protocol (https://) and domain.

Common Use Cases

Self-referencing canonical: Even if a page has no duplicates, it's good practice to point to itself:

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

Pointing to the original: If you syndicate content or have URL parameters creating duplicates:

<!-- On: https://example.com/product?sort=price&color=blue -->
<link rel="canonical" href="https://example.com/product">

Cross-domain canonical: If you republish content from another site:

<link rel="canonical" href="https://originaldomain.com/article">

Important Rules

  • Only one canonical tag per page
  • Use absolute URLs, not relative paths
  • The canonical URL should return a 200 status (not 404 or redirect)
  • Place it in the <head>, preferably early

Key Takeaway: The <link rel="canonical"> element in your document head tells search engines which URL is the master copy, preventing duplicate content penalties and consolidating ranking signals to one authoritative location.