Caffeine is a vasonstrictor (narrows vessels) so it clamps down on vessels in head that can cause headpain, ie headache. The opposite of a vasoconstrictor is a vasodilator (opens up vessels) such nitroglycerin which causes headaches. Another famous vasodilator, sildenafil, opens up some other important vessels (and also known to cause headaches)
Latest Answers