What is a canonical URL?
The "official" URL for a piece of content when multiple URLs could return the same content, declared via `<link rel="canonical" href="…">`.
Search engines have to handle the case where the same article is reachable at example.com/post, example.com/post?utm_source=twitter, example.com/post/, and m.example.com/post. The canonical link tells them: "treat all of these as variants of this one URL." Google then consolidates ranking signals onto the canonical version instead of splitting them across duplicates.
Setting canonical correctly is one of the highest-ROI SEO fixes for content-heavy sites. Common pitfalls: leaving the canonical pointing at staging, accidentally setting every page to canonical to the homepage, or self-referencing canonicals on UTM-parameterized URLs (correct) versus on truly different pages (wrong).
Canonical is a hint, not a directive. Google can override it if other signals contradict (e.g., you canonical to a 404). For absolute control over what gets indexed, use noindex instead.
In the wild
<link rel="canonical" href="https://www.context.dev/blog/post-title">on every variant of that post- Removing query strings from canonical URLs to consolidate UTM-tagged variants