Rainbows happen when sunlight and rain combine in a very specific way. Indeed, rainbows often indicate that the rain has passed. Generally, it will be sunny when you see a rainbow, but rain clouds (usually cumulonimbus ) will be just a short distance away. In order to see a rainbow, you'll need two ingredients: sunlight and raindrops.
Just after rainfall, the air in the atmosphere is fairly moist with water droplets still clinging on to some dust particles. When light falls on these water droplets and vapours, it gets dispersed into its constituent seven colours. These seven colours are in the shape of an arc and are known as a Rainbow.