Simply put, a solar panel works by allowing photons, or particles of light, to knock electrons free from atoms, generating a flow of electricity. Solar panels actually comprise many, smaller units called photovoltaic cells. (Photovoltaic simply means they convert sunlight into electricity.) Many cells linked together make up a solar panel.
Each photovoltaic cell is basically a sandwich made up of two slices of semi-conducting material, usually silicon — the same stuff used in microelectronics.
To work, photovoltaic cells need to establish an electric field. Much like a magnetic field, which occurs due to opposite poles, an electric field occurs when opposite charges are separated. To get this field, manufacturers "dope" silicon with other materials, giving each slice of the sandwich a positive or negative electrical charge.
Specifically, they seed phosphorous into the top layer of silicon, which adds extra electrons, with a negative charge, to that layer. Meanwhile, the bottom layer gets a dose of boron, which results in fewer electrons, or a positive charge. This all adds up to an electric field at the junction between the silicon layers. Then, when a photon of sunlight knocks an electron free, the electric field will push that electron out of the silicon junction.
A couple of other components of the cell turn these electrons into usable power. Metal conductive plates on the sides of the cell collect the electrons and transfer them to wires. At that point, the electrons can flow like any other source of electricity.
Recently, researchers have produced ultrathin, flexible solar cells that are only 1.3 microns thick — about 1/100th the width of a human hair — and are 20 times lighter than a sheet of office paper. In fact, the cells are so light that they can sit on top of a soap bubble, and yet they produce energy with about as much efficiency as glass-based solar cells, scientists reported in a study published in 2016 in the journal Organic Electronics. Lighter, more flexible solar cells such as these could be integrated into architecture, aerospace technology, or even wearable electronics.
There are other types of solar power technology — including solar thermal and concentrated solar power (CSP) — that operate in a different fashion than photovoltaic solar panels, but all harness the power of sunlight to either create electricity or to heat water or air.