The rainbow is formed in the sky after rain shower, due to tiny droplets of water which act as optical medium. When sunlight falls on them, it is totally internally reflected inside them and when comes out it got dispersed in its constituent colours. Thus, a rainbow is formed due to dispersion and total internal reflection.