Context : 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 . Aims : 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 . Methods : 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 . Results : A high signal-to-noise spectrum of the Crab pulsar was obtained from 300 nm to 2400 nm . The spectral index fitted to this spectrum is flat with \alpha _ { \nu } = 0.16 \pm 0.07 . For the emission lines we measure a maximum velocity of 1600 km s ^ { -1 } , whereas the absorption lines from the material between us and the pulsar is unresolved at the \sim 50 km s ^ { -1 } 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 . Conclusions :