Solar cells are made up of many layers of semiconductors with one layer having a positive charge while the next layer has a negative charge.
Photons that are available in sunlight, hit the cell and are reflected, transmitted, or absorbed.
When photons are absorbed by the negative layer of a photovoltaic cell, their energy is transferred to electrons in the atom of the cell.
With the increase in energy, the electron escapes the outer shell of the atom. The released electron moves to the positive layer naturally which makes the potential difference between the positive and the negative layer. When the two layers are connected to the outer circuit, electrons flow in the circuit, creating a current.