Sunlight coming to us in the form of white light is actually combination of seven colours. A rainbow is formed when white light passes through rain drops and splits into constituent seven colours. The rain drops act as prism and split the white light from sun. This is how different colours of rainbow are formed.