According to Super Smile, the ingredient in coffee that stains teeth is a chromogen. This is the same ingredient that is found in other colored foods and beverages, such as tea.
Super Smile points out that beverages like coffee, tea and red wine have food compounds in them known as tannins, which boost the ability of a chromogen to stick to enamel. Also, beverages that are either extremely hot or cold make it easier for chromogens to stain and penetrate enamel. This is because the change in temperature causes teeth to expand and contract. Adding just a splash or two of milk to coffee lessens its staining ability.