Yes, you can legally drive in high heels, but this isn’t recommended, as there are many risks around doing so.
For instance, a stiletto might slip and get caught under the pedals, whereas a heavier heel will be heavier on the pedals and will require applying less pressure than you may be used to when wearing flatter shoes.
Before driving in heels, you might have to push your seat back to accommodate your increased stature, which can impact the safety of your driving if you are not used to this.
Ultimately, whether you can drive in high heels is a matter of personal judgement. However, it may be wise to keep a pair of flat shoes in your car for driving.