Sunlight is made of different colours, and water in the atmosphere splits it up.
To know about the rainbow, we need to start with the nature of sunlight.
The light from the sun is actually made of different colours – violet, indigo, blue, green, yellow, orange and red (VIBGYOR). These colours form the spectrum, a range of colours that our eyes can see. On the long journey that the sun’s rays make from the sun to the earth, the different kinds of light in the spectrum mix together and form the whitish sunlight that we see.
Each of these colours have different energies, and each of them move through the atmosphere at slightly different speeds. When they hit a raindrop, each of the colours bend, instead of coming toward the earth in a straight line. On one side of each raindrop, the white light is complete; on the other side, the white light is split into VIBGYOR, forming a rainbow. This is because each of the colours are bent by the rainbow, to different levels. Glass also does the same with light, and a triangular piece of glass that can split light is called a prism. In our atmosphere, raindrops are acting as prisms.
You can make your rainbow! Ask your parents for a compact disk (CD). If you hold it against sunlight, with the label side facing down, you will be able to see a rainbow. This is because the smooth surface of the CD has many many prisms on it, all of which are making rainbows.
Here is a web-page showing SIX different ways to make rainbows.