Sometimes when it rains, you can see a rainbow. A rainbow appears only when it is raining and sunny at the same time. But the sun, the clouds and you, have to be at a certain position in order to observe a rainbow.
This is how and why rainbow appear: Sunlight contains many different colors. Actually, it contains an infinite number of colors, all colors which exist. This is the sunlight’s visible spectrum, and it ranges from red to violet. But all of these colors together, as in normal sunlight, appear white. Raindrops separate all the different colors so that one can observe them individually. Therefore a rainbow has all these colors.
The reason for the color separation is that light breaks when it penetrates the droplet of water. To break light means that the light doesn’t go straight through the surface of the raindrop; it gets bent. In physics this effect is called light refraction. Each color gets bent to different degrees. For rainbows to appear, the white sunlight gets separated into the individual colors of the spectrum inside the raindrops. The whole process of separating the white light into its different colors is shown the figure below.
When the white light with all its colors enters the raindrops it already gets separated into the different colors, Then, at the back of the raindrop it gets reflected. While exiting the raindrop, the light gets broken again. You can see from the diagram that the sun needs to be behind you whereas the rain needs to be in front of you in order to observe the individual colors.
This separation of light happens in all the raindrops of the raincloud, which are at a specific angle between you and the direction of sunlight. All of these different colors form the rainbow.
You can also make a tiny rainbow yourself by spraying water outside on a sunny day with the sun in your back. It looks great.