To provide better experiences for your worldwide customers, you have to display pages in their local language. The most important pages on your website are product and category pages where customers stay longest.
Sometimes, search engines give priority to pages in one language and ignore the other alternatives. So to make them all rank on SERP you need hreflang tags.
To simplify the process and add them easier and faster, you can use Alternate Hreflang Tags Extension. Moreover, it automatically sets alternate hreflang tags for the product and categories pages.
So to add hreflang tags to Magento 2 product and category pages all you need to do is go to Stores > Configuration > Magefan Extensions > Alternate Hreflang > General and enable them in a corresponding field.
Once you save the configuration, Magento 2 Hreflang Tags extension will generate hreaflang tags for Magento 2 product and category pages.
Note: In case you have multi-website Magento, duplicated the same product for each website (you don't use the same product ID but create different product entities for each website) and want to connect the product pages with the alternate tags there is a separate Alternative Store View Localizations section for each product.
You need to go to Catalog > Products and set the hreflang tags for the products you are interested in.
The same works for Magento 2 categories. You define the alternate hreflang tags for them only in case the duplicated category has different IDs for different websites.
The best thing about Magento 2 Hreflang Tags extension is it doesn't require you to enter any language or country codes manually. Learn more about the full list of options in hreflang tags configuration guide.