Pulsars are well studied all over the electromagnetic spectrum, and the Crab pulsar may be the most studied object in the sky. Nevertheless, a high-quality optical to near-infrared spectrum of the Crab or any other pulsar has not been published to date. Obtaining a properly flux-calibrated spectrum enables us to measure the spectral index of the pulsar emission, without many of the caveats from previous studies. This was the main aim of this project, but we could also detect absorption and emission features from the pulsar and nebula over an unprecedentedly wide wavelength range. A spectrum was obtained with the X-shooter spectrograph on the Very Large Telescope. Particular care was given to the flux-calibration of these data. A high signal-to-noise spectrum of the Crab pulsar was obtained from 300 to 2400nm. The spectral index fitted to this spectrum is flat with alpha_nu=0.16 +- 0.07. For the emission lines we measure a maximum velocity of 1600 km/s, whereas the absorption lines from the material between us and the pulsar is unresolved at the 50 km/s resolution. A number of Diffuse Interstellar Bands and a few near-IR emission lines that have previously not been reported from the Crab are highlighted.