The rainbow effect can be observed whenever there are water mists in the air and sunlight shining from behind the observer. The most spectacular rainbow displays when half of the sky is still dark with draining clouds and the observer is at a spot with clear sky overhead. Another common place to see the rainbow effect is near waterfalls. The effect can also be artificially created by dispersing water-vapour into the air during a sunny day.
In a very few cases, a moonbow, or night-time rainbow, can be seen in the mists of certain waterfalls on clear, strongly-moonlit nights.
The rainbow's appearance is caused by dispersion of sunlight as it is refracted by (approximately spherical) raindrops. The light is first refracted as it enters the surface of the raindrop, undergoes total internal reflection from the back of the drop, and is again refracted as it leaves the drop. The overall effect is that the incoming light is reflected back at an angle of about 40-42°, regardless of the size of the drop. Since the water of the raindrops is dispersive, the amount that the sunlight is bent depends upon the wavelength (color) of the light's constituent parts. Blue light is refracted at a greater angle than red light, but because of the reflection from the back of the raindrop, the red light appears higher in the sky, and forms the outer color of the rainbow.
The rainbow does not actually exist as a location in the sky, but is an optical illusion whose apparent position depends on the observer's location. All raindrops refract and reflect the sunlight in the same way, but only the light from some raindrops reaches the observer's eye. These raindrops are perceived to constitute the rainbow by that observer. Its position is always in the opposite direction of the sun with respect to the observer, and the interior is actually a magnified image of the sun, which can be seen to be slightly brighter than the exterior. The bow is centered on the shadow of the observer's head, appearing at an angle of approximately 40-42° to the line between the observer's head and its shadow. Sometimes, a second, dimmer rainbow is seen outside the primary bow, caused by a double reflection of the sunlight inside the raindrops, and appears at an angle of 50-53°. Because of the extra reflection, the colors of the bow are inverted compared to the primary bow, with blue on the outside and red on the inside.
The rainbow has a place in legend due to its beauty and the difficulty in explaining the phenomenon before Galileo's treatise on the properties of light. It is mentioned in the Bible, Genesis 9  (http://wwwbible.com/kjv30/B01C009.htm) , as a sign of God's covenant with mankind. In Greek mythology, it is a path made by a messenger (Iris) between Earth and Heaven. The Irish leprechaun's secret hiding place for his crock of gold is usually said to be at the end of the rainbow. In Chinese mythology, the rainbow was a slit in the sky sealed by a goddess using stones of seven different colors.
The rainbow has also been used in more contemporary settings, such as the song Over the Rainbow in the musical film of The Wizard of Oz, and in selling Lucky Charms by alluding heavily to leprechaun mythology.