The inversion itself is usually initiated by the cooling effect caused when cold water on the surface of the ocean interacts with a comparatively warm air mass.
The lower layer will also gradually increase its humidity by evaporation of the surface water, as well as by the effect of the cooling itself, since cooler air holds more moisture.
[1][2] Clouds and potentially fog can form within a marine layer when the water-saturated air is cooled and reaches a humidity of 100%, where it will then condense and turn into water droplets.
[3] In the case of coastal California, the offshore marine layer is enabled by the cold relative sea surface temperatures of the Pacific Ocean.
Marine layers often form on the west coasts of continents, where upwelling usually occurs, and where there is a relatively warm air mass moving over a cool body of water.