Leaves contain 3 types of pigments: chlorophyll which is green, carotene which is yellow, and anthocyanin which is red.
Chlorophyll make the leaves appear green because it absorbs Red and Blue light from the sunlight.
Carotene make the leaves appear yellow because it absorbs Blue-Green and Blue light from the sunlight.
Anthocyanin make the leaves appear red because it absorbs Blue-Green, Blue and Green light from the sunlight.
Chlorophyll are comparatively unstable and is continuously regenerated via sunlight and warm temperature. When climate gets colder and chlorophyll or green color decline, the more stable carotene the yellow pigments appear and leaves turn yellow. As the leaves dry, the increased level of sugar reacts with some proteins and sunlight to form anthocyanin the red pigment, making the leaves turn red. Anthocyanin are PH sensitive and it can be bright red in ripe apples or purple in ripe grapes.