The outer layer of a tooth is called the enamel. The color of natural teeth is created by the reflection and scattering of light off the enamel, combined with the color of the dentin under it. Your genes affect the thickness and smoothness of the enamel. Thinner enamel allows more of the color of the dentin to show through. Having smoother or rougher enamel also affects the reflection of light and therefore the color.
Every day, a thin coating (pellicle) forms on the enamel and picks up stains. Tooth enamel also contains pores that can hold stains.
The most common reasons for teeth to get yellow or stained are: