A morning glory leaf soaking up sunlight. Little pores (stomata) on the surface of the leaf pull in CO2 from the atmosphere.
Roots extract water (H2O) from the soil and special tissues (xylem) transport this water to the leaves.
Sunlight provides the energy for the following reaction called photosynthesis:
6 CO2 + 6 H2O ==> C6H12O6 + 6 O2
Six molecules of carbon dioxide (CO2) plus 6 molecules of water (H2O) will yield one molecule of sugar (glucose - C6H12O6) and six molecules of oxygen (O2). The oxygen is released back into the atmosphere through the stomata and the glucose provides energy for cells (animals get glucose by eating and breaking down food) and are the building blocks of starches.
Earth's early atmosphere was esentially carbon dioxide (like those of Venus and Mars today at 96-97% CO2). Early in the history of life (over 3 billion years ago), a group of bacteria called the cyanobacteria, developed the ability to do photosynthesis. Over a couple of billion years, their then poisonous waste product, molecular oxygen (O2), gradually built up in the atmosphere allowing for the evolution of animal life (and eventually us).