Pure genetic traits and environment.
People, whether genetically fairer than others, will darken in sunny conditions. This is natural and right. However, we are all also genetically predisposed to the colour of our skin for which we are born with. This is perfectly natural and right too.
As homeosapians have evolved and changed over time, we have adapted to our environments. This is a natural survival gene kept within the gene pool of families, handed down from generation to generation over time. Those fairer skin, for example, were probably more likely to either darken or die out from diseases of harmful sun rays in hot climates. Those with high melantonine levels (associated with skin pigmentation) genetics, therefore, were more likely to survive the sun's effects and live longer, thereby breeding stronger genetic stock associated with skin.
On the other side, those with fairer skin were probably more adapt to colder climates and thrived when the sun wasnt as harmful compared to hot climates. They then breed more, thereby favouring within a culture the paler skins.
Food also has a lot to do with skin colour and tones. A healthy diet, for example, rich in fish and olive oils, can help with sun protection and the overall look of the complexion: