What is a canonical URL?
A canonical URL is the preferred URL for a webpage. The meta tag “link rel” is how you tell search engines what the canonical URL is for each of your website pages. The canonical meta tag is placed in the <head> of your webpage, and looks like this:
Why are canonical URLs used?
Canonical URLs are an SEO technique for managing duplicate content.
When should I use a canonical URL?
Every page of your site should have a canonical URL meta tag.
Why are canonical URLs sometimes different from the browser URL?
One canonical URL example is when your website has duplicate content (multiple pages with very similar content). In this situation it is best practice to choose one as the canonical (preferred) URL. Even though one page does not redirect to the other (as is best practice when managing the www and non-www version of your site) setting a canonical URL tells search engines which page to index, and which to ignore, thus avoiding any SEO damage.
I use canonical URLs to avoid the negative SEO effects of duplicate content because the front page of Surfnetkids.com https://www.surfnetkids.com has the same content has the front page of my Surfnetkids Resources blog https://www.surfnetkids.com/resources/. So, if you view the source of the latter URL, you will see the canonical URL is set to the former URL.
Some site structures create duplicate content because certain pages can be reached via multiple paths: such as https://www.example/people/biographies and https://www.example.com/history/biographies/. Canonical URLs are the SEO technique that solves this kind of duplicate content.
Yet another use of canonical URLs is on AMP versions of posts, where the canonical URL points to the desktop/mobile version (the non-AMP version). You can take a look at this in the source code for the AMP version of this post: https://www.wordher.com/glossary/canonical-url/amp/
Canonical URLs can also point to original posts on external websites. Suppose you wrote an original guest post for someone else’s blog but you also want to publish it on your site. In fairness to the other site (since you promised them an original, unique guest post) you could publish it on your blog (so your regular readers will see it) but set the canonical URL to be the external site so the search engines will only send traffic to them.
The Yoast SEO plugin is one way of setting canonical URLS (it’s what I use) but there are other plugins that do the same thing.