Plants produce oxygen as a byproduct of photosynthesis, the process that plants and other organisms use to create usable energy. Photosynthesis consists of carbon dioxide and water reacting in the presence of energy from sunlight, which produces glucose and oxygen. Glucose is a simple sugar molecule that can be used by cells for energy.
Unlike human skin tissue, green plants contain chlorophyll on their leaves, which allows them to absorb energy directly from the sunlight. While it is not immediately usable by the cells in the plant, it can be converted into glucose via photosynthesis. Plants get the required carbon dioxide from the air, and the water needed for photosynthesis through their roots.