XRF works by exposing a sample to high-energy X-rays. When these X-rays interact with the atoms in the sample, they dislodge inner-shell electrons. The resulting vacancies are filled by electrons from higher energy levels, releasing secondary X-rays in the process. These secondary X-rays have energies characteristic of the elements present in the sample, allowing for their identification and quantification.