A solar cell is made of semiconducting materials, such as silicon, that have been fabricated into a p–n junction. Such junctions are made by doping one side of the device p-type and the other n-type, for example in the case of silicon by introducing small concentrations of boron or phosphorus respectively.
In operation, photons in sunlight hit the solar cell and are absorbed by the semiconductor.  When the photons are absorbed, electrons are excited from the valence band to the conduction band (or from occupied to unoccupied molecular orbitals in the case of an organic solar cell), producing electron-hole pairs. 
If the electron-hole pairs are created near the junction between p-type and n-type materials the local electric field sweeps them apart to opposite electrodes, producing an excess of electrons on one side and an excess of holes on the other. When the solar cell is unconnected (or the external electrical load is very high) the electrons and holes will ultimately restore equilibrium by diffusing back across the junction against the field and recombine with each other giving off heat, but if the load is small enough then it is easier for equilibrium to be restored by the excess electrons going around the external circuit, doing useful work along the way.
An array of solar cells converts solar energy into a usable amount of direct current (DC) electricity. An inverter can convert the power to alternating current (AC).
The most commonly known solar cell is configured as a large-area p–n junction made from silicon. Other possible solar cell types are organic solar cells, dye sensitized solar cells, perovskite solar cells, quantum dot solar cells etc. The illuminated side of a solar cell generally has a transparent conducting film for allowing light to enter into the active material and to collect the generated charge carriers. Typically, films with high transmittance and high electrical conductance such as indium tin oxide, conducting polymers or conducting nanowire networks are used for the purpose.