First, we have to enable the group comparison feature. Go to the Catalog Settings > Attributes and check the Group Comparison checkbox:
Once you enable it, you will see an option to assign the comparison group name on the product edit screen:
Adding a product to the comparison group will enable the comparison tab or section on the product page.
The priority box will set the product priority in the comparison group. Without priority, the products are sorted by product name.
All the products from the same group will be automatically compared in the comparison tab.
This is how it will look with Compare Only Attributes option enabled: