There are a number of different ways by which fog can form. Regardless of the way it's formed, the science behind fog is the same. Fog occurs when the air at the surface is either completely or nearly completely saturated with water. Essentially, fog is a cloud that forms down at the surface.
Fog is a fairly uncommon occurrence here in the desert. This is mainly because it's oftentimes so dry here. As a general rule of thumb, when the air temperature and dew point are within three degrees of each other, fog is able to form. That was the case in many parts of the valley this morning.