The cortex is the layer of the hair responsible for its color. This layer contains melanin, the pigment that determines hair color. Melanin is produced by cells called melanocytes and comes in two main types: eumelanin and pheomelanin. Eumelanin produces darker colors like black and brown, while pheomelanin produces lighter colors like blonde and red. As we age, melanocytes die, leading to the reduction of melanin and the appearance of gray or white hair.