Some deserts are formed in regions that are cut off from the ocean by high mountains. Winds carry wet air from the ocean to the land. When the air climbs over high mountains it loses most of its moisture and when it falls down on the other side it becomes very warm and dry. Deserts on the western coast of North America were formed by such winds.
Many areas have become dry because they are too far away from the ocean. Air loses its moisture by the time it reaches places that are thousands of kilometres from the coast.
Deserts can also develop near the coast. Cold water moves from the Antarctic northwards along the African and South American coast. The warm air in these places cools down and mixes with the cool water. There is a lot of fog , but no rain. That’s why the Atacama desert in Chile and the Namib desert in Africa are among the driest deserts in the world.