According to Met Office, fog forms when numerous small water droplets become suspended in the air. Fog happens most often in heavily polluted industrial areas where water can cling to the small pollution particles in the air.
Met Office notes that the way fog forms depends on the type of fog. One of the most common types is radiation fog, which typically happens in winter during clear-sky conditions. When the thermal radiation in the atmosphere cools the air near the surface of the ground, air becomes less able to hold moisture and fog forms. Fog also forms on hills and valleys due to the different altitudes.
According to Wikipedia, fog is always low-lying due to the fact that its density is generally greater than that of the surrounding air. Fog is almost always formed close to bodies of water, ranging from small lakes and rivers to large oceans. As Met Office explains, evaporation fog is a common type of atmospheric phenomenon that occurs when cold air passes over warm water or very moist land, such as a marsh. The evaporation of the warm water into the lower layers of the air causes it to cool and produce a thick fog.