Canonical tag prevents indexing of duplicate web pages indexing. If you have multiple web pages with same content, then by using rel="canonical" tag you can define which pages should be indexed by search engines (crawlers).
Canonical tag syntax is as below:
<link rel="canonical" href="https://example.com/page-name/
Example to use: There are two webpages pagename1 and pagename 2 with same content (for some purpose) then you can control which page should index. If pagename1 needs to index then pagename2 should have canonical tag which points pagename1 URL .
Canonical tag resides within <head></head> tag, because this is only for crawler purpose but not for user.