In STXM, a focused X-ray beam is scanned across a sample. As the X-rays pass through the sample, they interact with the atoms, causing them to absorb energy. This absorption is measured to produce images and spectra that reveal the distribution and chemical state of the elements within the sample.