Fog is caused by an inversion, i.e. warmer air over colder one. When it happens, the air doesn't rise and as the earth cools down at night by radiation back into space, the temperature drops under dew point and moisture in the air condenses into tiny droplets we call the fog.
That's the most common cause for fog, but there are others:
Orographic fog. Pretty much the same but caused by the air rising over a mountain. Mind you, they call it fog, up on the mountain, and we call it cloud, down in the valley.
Advection fog. When moist and mild air moves from over the sea or a lake, toward a much colder land, it condenses and form fog. In the US, this is often called 'lake effect' fog because it happens often on the shore of the Great Lakes. If it is very cold, it even produces 'lake effect snow.'
Sea smoke. Simply the fog that arises above a coastal area when the temperature is very cold, during the late autumn and the sea / lake is still warmer. It's pretty much like the "smoke" of...