Solar panels work by converting sunlight into electricity. Sunlight is composed of particles called photons. When photons strike a solar panel, they knock electrons loose from their atoms. This process is called the photovoltaic effect.
The solar panel is made up of many individual solar cells. Each solar cell is made of two layers of semiconductor material. One layer has an abundance of electrons, while the other layer has a deficiency of electrons. This creates an electric field between the two layers.
When photons strike the solar cell, they knock electrons loose from the atoms in the semiconductor material. The electric field then pulls the electrons towards the side of the solar cell with the deficiency of electrons. This flow of electrons generates electricity.