Somewhat Similar to the sea breeze, the marine layer also represents a difference between a cool, moist airmass and a warmer airmass. Unlike the sea breeze, which reforms almost everyday along the east coast in Summer, the marine layer can persists for days and weeks along the west coast, particularly Southern California.
The reason is the water along the west coast of the United States comes from the Gulf of Alaska and is much cooler than at the same latitude along the east coast where the Gulf Stream brings tropical water north. The surface temperature of the water off the California coast can be as much as 30°F (17°C) or more lower than at the same latitude on the east coast. The colder water means the air in contact with the water is colder and therefore is more dense.
When the air well above the water is warmer than the water, as it is normally for all seasons except winter but most common in late spring/early summer, a temperature inversion develops, where instead of the air cooling with increasing elevation the air actually increases in temperature with height. The cooler air below the inversion is called the marine layer and is cooled to the point at which clouds form. Because of its persistence in early Summer, the people in Southern California it is often refer to it as the "May Gray" or "June Gloom".
However, it is not just a West Coast phenomena, it can occur near any large body of water such as the Great Lakes region when the water temperature is significantly colder than the air moving over it.
The depth of the marine layer depends upon the large scale weather patterns that pass overhead. High pressure systems (at 15,000 to 30,000 feet) tends to squish the marine layer down near the surface. When the inversion is very strong and relatively shallow, the coastal clouds and foggy weather will be confined to the beaches with warm, sunny conditions beginning just a mile or so inland.
In Summer, it is not uncommon for someone to drive across the San Francisco's Golden Gate bridge in fog with a temperature in the upper 50s to lower 60s only to go to the top of Mount Tamalpais, just a few miles north of the bridge (elevation 2,600 feet), and have clear skies with a temperature in the 80s or even the lower 90s because of moving above the cool marine layer.
As the pressure aloft decreases, the downward forcing on the marine layer decreases and the marine layer begins to lift. Near the beach, the fog lifts into a low cloud layer. The leading edge of the marine layer extends farther inland pushing the fog inland.
Further lifting of the marine layer will allow the cooler air to spill over the mountains into the interior valleys. Sometimes, if the air in the low pressure system aloft is cold enough, the inversion that defines the top of the marine layer will dissipate and so will the marine layer. Because of this, often the maximum daily temperatures in the San Joaquin and Sacramento Valleys of California will undergo a roller coaster effect.