This review discusses how low-energy valence excitations created by swift electrons can render information on the optical response of structured materials with unmatched spatial resolution. Electron microscopes are capable of focusing electron beams on subnanometer spots and probing the target response either by analyzing electron energy losses or by detecting emitted radiation. Theoretical frameworks suited to calculate the probability of energy loss and light emission ͑cathodoluminescence͒ are reconsidered and compared with experimental results. More precisely, a quantum-mechanical description of the interaction between the electrons and the sample is discussed, followed by a powerful classical dielectric approach that can be applied in practice to more complex systems. The conditions are assessed under which classical and quantum-mechanical formulations are equivalent. The excitation of collective modes such as plasmons is studied in bulk materials, planar surfaces, and nanoparticles. Light emission induced by the electrons is shown to constitute an excellent probe of plasmons, combining subnanometer resolution in the position of the electron beam with nanometer resolution in the emitted wavelength. Both electron energy-loss and cathodoluminescence spectroscopies performed in a scanning mode of operation yield snapshots of plasmon modes in nanostructures with fine spatial detail as compared to other existing imaging techniques, thus providing an ideal tool for nanophotonics studies.