We review applications of string theory to cosmology, from primordial times to the present-day accelerated expansion. Starting with a brief overview of cosmology and string compactifications, we discuss in detail moduli stabilisation, inflation in string theory, the impact of string theory on post-inflationary dynamics (reheating, moduli domination, kination), dark energy (the cosmological constant from a string landscape and models of quintessence) and various alternative scenarios (string/brane gases, the pre big-bang scenario, rolling tachyons, ekpyrotic/cyclic cosmologies, bubbles of nothing, S-brane and holographic cosmologies). The state of the art in string constructions is described in each topic and, where relevant, connections to swampland conjectures are made. The possibilities for novel particles and excitations (axions, moduli, cosmic strings, branes, solitons, oscillons and boson stars) are emphasised. Implications for the physics of the CMB, gravitational waves, dark matter and dark radiation are discussed along with potential observational signatures.