The rainbow is an optical phenomenon that is formed due to the separation of colors that form sunlight. It can be observed whenever there are water droplets suspended in the atmosphere and sunlight is shining above the observer at low altitude or angle, that is, it can happen during or after a rain. This event occurs because of the dispersal from light.
Dispersal is the phenomenon that causes a wave to split into several spectral components.
Sunlight is a wave of white light formed by various colors, when this light falls on a drop of water the light rays penetrate it and are refracted, thus suffering dispersion. The colored light beam inside the drop is reflected on its internal surface and undergoes a new refraction process, which causes the separation of colors that an observer can see. It is evident that this dispersion occurs with all water droplets that are on the surface receiving light from the Sun.
The rainbow does not exist, it is an optical illusion whose visualization depends on the relative position of the observer. It is important to point out that all water drops refract and reflect light in the same way, however, only some colors resulting from this process are captured by the eyes of the observer.
By Marco Aurélio da Silva
Source: Brazil School - https://brasilescola.uol.com.br/fisica/formacao-um-arco-iris.htm