Progress in electron-beam spectroscopies has recently enabled the study of optical excitations with combined space, energy and time resolution in the nanometre, millielectronvolt and femtosecond domain, thus providing unique access into nanophotonic structures and their detailed optical responses. These techniques rely on ~1–300 keV electron beams focused at the sample down to sub-nanometre spots, temporally compressed in wavepackets a few femtoseconds long, and in some cases controlled by ultrafast light pulses. The electrons undergo energy losses and gains (also giving rise to cathodoluminescence light emission), which are recorded to reveal the optical landscape along the beam path. This Review portraits these advances, with a focus on coherent excitations, emphasizing the increasing level of control over the electron wavefunctions and ensuing applications in the study and technological use of optically resonant modes and polaritons in nanoparticles, 2D materials and engineered nanostructures.