Tiny water droplets suspended in air have greater density than air. The sunlight when changes medium, undergoes total internal reflection through these droplets thereby splitting in its component colours (since wavelength of each colour is different) and hence, results in rainbow formation. Thus, dispersion and total internal reflection together results in rainbow formation.