The color scheme of traffic lights is the result of borrowing from railroad signaling schemes of the time, according to Mental Floss. The first traffic lights were green and red, and amber later became the third color to provide a buffer between the "stop" and "proceed" signals. This was to prevent accidents due to sudden light changes as well as to allow the policemen time to switch the lights manually.
The railroad system in Great Britain used a variety of color codes to provide information to engineers, but different railroads used different signals. In 1841, the country standardized the signaling system, with red as a warning sign, white indicating clear track ahead and green representing "proceed with caution."
The foot and carriage traffic outside the Houses of Parliament in London necessitated the first traffic light in 1868, a manual signal that used red and green gas lamps at night. This color scheme became the default, but the development of the automobile highlighted a new problem. A sudden change from green to red in a four-way intersection had the potential to provoke an accident, and mistimed signals could lead to chaos. Detroit, Mich., established the first three-color traffic light in 1920, inserting a yellow "caution" light between the red and green signals as a safety measure.