Sunlight is best, but few of us spend the solid hour daily with sun hitting enough of our exposed skin to get all of the Vitamin D we need. For the rest of us, the vast majority of us, we are left with the pill to make up the difference.
I did what I could to get good sun exposure last year in those prime hours. Also gave me fresh air exposure and UV.
I’m checked regularly for skin cancer. I’m outdoors a lot, but usually with long sleeves and pants. Not sure my face and hands generate enough vitamin D so I supplement. Costs me a few cents a day.