Up to Magento 2.2 Version, We can create product attributes programmatically using the InstallData.php file.
Using dynamically create product attribute save the time for creating attribute manually using the admin panel.
If you are creating an extension package and you need product attribute at that time below code snippet will be helpful for creating Product attribute.

Thank you for this detailed guide.
I always hunt for good tutorials about Magento and your’s is one of them. I have seen some more guides during my research and found one more useful guide which has shown the method for Magento 1 as well as for Magento 2. Here it is: https://magenticians.com/create-magento-2-attribute/
Kudos!
Thank you for this detailed guide.
I always hunt for good tutorials about Magento and your’s is one of them. I have seen some more guides during my research and found one more useful guide which has shown the method for Magento 1 as well as for Magento 2. Here it is: https://magenticians.com/create-magento-2-attribute/
Kudos!