The formation of a rainbow is primarily due to dispersion, as it involves the separation of light into its constituent colors when it passes through water droplets in the atmosphere, it is refracted and dispersed due to varying wavelengths.