Refraction is the change in direction of light when passing from one medium to another of different density. Snell's law states that the ratio of sines of the angle of incidence and refraction is equal to the ratio of refractive indices of the two media. Due to refraction, the sun appears above the horizon before actual sunrise and remains visible after sunset. Stars twinkle because their light refracts through Earth's fluctuating atmosphere, while planets do not twinkle as they appear as extended sources when viewed. Refraction also causes mirages and the apparent flattening of the sun near the horizon.