According to Understanding Evolution, the main purpose of stomata is to enable carbon dioxide to enter the leaf rapidly and allow oxygen and water vapor to exit out of the leaf quickly. They primarily control transpiration and gas exchange with the atmosphere.
According to Kimball's Biology Pages, stomata are tiny aperture structures within the epidermis, and they are located on the outer leaf skin layer of plants. Most stomata are found in the lower epidermis. Each stoma is flanked by two guard cells, which are specialized cells that regulate the opening and closing of the stomata and control the gas exchange between the leaf and the air.
According to the Encyclopedia of Earth, stomata are essential for photosynthesis and respiration to take place. Photosynthesis, which is the process of manufacturing food, occurs in the leaves of plants. Carbon dioxide, water and sunlight are needed for this process. Stomata open when there is sunlight and allow carbon dioxide to diffuse into the leaf, where the gas is converted to sugar. Meanwhile, water vapor exits the leaf through the stomata; this process is called transpiration.
The Encyclopedia of Earth explains that stomatal movement depends on changes in the water pressure of the guard cells. The water pressure is controlled by the mechanics of the walls of the guard cells. Stomata open or close whenever guard cell volumes increase or decrease. They swell up, bend away from each other and open up when the guard cells are filled with water; at dry times, the guard cells remain closed.