How a solar cell works
Click here for a simpler version of how a solar cell works
A solar cell is made of mostly silicon while containing small amounts of phosphorus and boron. Silicon, phosphorus, and boron are all neutral atoms (they have an equal amount of electrons and protons), so they can't produce energy normally. However, electrons naturally move around and exit atoms, going into others. Electrons have a negative charge, so when one leaves an atom, the ratio of protons to electrons increases and the atom has a positive charge. When an electron enters an atom, the opposite happens, and the atom has a negative charge. Either of these scenarios is voltage.
A positive charge has an electric field that pushes out from the atom in all directions. A negative electric field pulls towards the atom in all directions.
A solar cell has two layers in order to work. Both layers have silicon, but the top layer has phosphorus and the bottom has boron as well. Phosphorus has 15 electrons and 15 protons, while boron has 13 of each. The line where the two layers meet is called the p-n junction. Immediately after the layers are constructed, electrons move from the top layer to the bottom layer to balance out the number of electrons. This leaves positive atoms behind in the top layer. This happens mostly near the p-n junction. As more electrons move towards the bottom, the electric field between the layers strengthens.