Blue eyes are caused by a defective gene, called the OCA2 gene. This gene controls the production of melanin, the pigment that causes brown eyes to be brown and also that causes our skin and hair to be brown.
If the OCA2 gene is completely borked, you’re an albino (well, technically one type of albino - there are several types involving several different genes, but that’s not worth going into here). With a completely defective OCA2 gene, your body won’t produce any melanin. You’ll have blue eyes (possibly appearing pink in certain lighting conditions), white hair, very white skin, and all sorts of vision problems. It turns out that melanin is important to the formation of your eyes, and without melanin the retinas and the optic nerves don’t develop properly. For reasons that I personally also don’t understand, albinism also results in problems with the eye muscles, leading to rapid uncontrolled eye movements, weak eye muscles, and both eyes not always facing the same direction, all of which contribute to even worse overall vision.
People with blue eyes don’t have an OCA2 gene that is completely whacked out, but our OCA2 gene doesn’t work the way that it should. Since this defective OCA2 doesn’t allow the body to fully produce melanin, those of us who have this blue eye defect end up with lighter skin and blue eyes. We don’t however end up with all of the vision problems that albinos have with their completely futzed version of OCA2.
Your skin color doesn’t just depend on the OCA2 gene. There are other genes involved, such as the SLC24A5 gene (that I had to look up because I can remember OCA2 but I can’t remember SLC24A5 or any of the other related genes…). But overall, lighter skin color rapidly spread through the population of northern Europe, for reasons that aren’t fully understood. The leading theory is that lighter skin allows better absorption of sunlight, leading to better vitamin D production in lighter skinned people. Or to put it more simply, us light-skinned folks end up being healthier in places like northern Europe where the weather sucks.
Blue eyes are often seen as attractive, so there may be some sexual selection to it as well, but mostly it’s thought to be the lighter skin and vitamin D that made the OCA2 defect spread so quickly through northern Europe.
The vitamin D theory also helps to explain why lighter skin developed at least twice, possibly more. Asians with lighter skin don’t have the same genetic defects as Europeans, which proves that light skin at least evolved separately in Europe and Asia. There is more diversity in the Asian genes that cause lighter skin, so lighter skin might have actually evolved more than once in northern Asia. What is important to the vitamin D theory is that light skin in Asia developed in northern Asia, so again we’re back to vitamin D making lighter skinned people healthier in places where the weather sucks.
Seems like a good theory to me.