In order to get familiar with how solar panels work, we need to introduce two heroes to the story: the photon and the electron.
The light energy coming in from the Sun arrives in the form of an electromagnetic wave. Light does not only behave as a wave. In some situations, light also behaves like it is made up of smaller particles, known as photons. A stubborn law of physics is that things are always made of smaller things. Just as material objects are made of atoms, light is made of photons! Photons carry a lot of energy with them as they move.
An even smaller part of the atom is the electron, which carries negative charge. The electron is the second hero in our story. In some elements, like silicon, the electrons are loosely held to the atom. The slightest push of energy can knock an electron out of the atom.
A photovoltaic cell has two main layers, both made of a compound known as a semiconductor, which is rich in silicon. The top layer is silicon mixed with phosphorus, in a process known as doping. This gives the layer many extra electrons. The bottom layer is silicon mixed with boron, giving the layer fewer electrons than normal. Electrons are negatively charged, and like charges repel. When lots of like charges are stuck in one place together, they want to escape that place.