The phenomenon of graying hair is still somewhat mysterious. Hair color is determined by a pigment known as “melanin” that’s dispersed through the center of each individual hair shaft. The specific color is determined by the number, size, and — most importantly — color of the pigment particles. Darker hairs show higher trace amounts of copper, which indicates that the metal-based melanin molecules are more highly developed in dark-haired people.
For some unknown reason the cells that produce melanin, known as “melanocytes,” can decelerate or cease production completely. When this occurs, the hair begins to lose its color, turning yellow and then gray. Air bubbles, which sometimes inexplicably find their way into the hair shaft, also play a role in graying by preventing the passage of melanin. Graying seems to be genetically determined, but the correlation is not all that certain. The process is the same for both light- and dark-haired people, but the pigment loss, obviously, is more noticeable in people with darker hairs.
(Source: The Straight Dope)