Fog forms when water vapor is suspended in the atmosphere at an altitude where visibility is affected. As clouds are also suspended water vapor, you can think of fog as simply a cloud that is close to the ground. Fog appears when moist air near the earth's surface is cooled during the night, and breezes push cooler air underneath this layer. This type of fog is called radiation fog.
Typically, fog forms when the relative humidity is near 100 percent, and it is not considered fog unless it reduces visibility to less than 1 kilometer (0.6 miles). Fog also forms when warm air moves over a colder region. This is known as advection fog, and happens frequently in coastal areas when warm moist air moves onto cooler land. A similar variety is steam fog, which forms over water when a current of much colder air moves over a body of water such as a lake.
It is possible for the temperature of the water droplets in fog to be below freezing. This supercooled water tends to freeze on contact with surfaces, depositing a thin layer of ice known as rime. This type of fog is called freezing fog. Other varieties include precipitation fog, which forms when rain evaporates as it falls into dry air; hail fog, which occurs when a hailstorm encounters a warm humid layer of air; and upslope fog, a result of condensation due to the drop in air pressure as the wind travels up a slope to a higher altitude.