The most common approaches to generating power from sunlight are either photovoltaic, in which sunlight directly excites electron-hole pairs in a semiconductor, or solar-thermal, in which sunlight drives a mechanical heat engine. Photovoltaic power generation is intermittent and typically only exploits a portion of the solar spectrum efficiently, whereas the intrinsic irreversibilities of small heat engines make the solar-thermal approach best suited for utility-scale power plants. There is, therefore, an increasing need for hybrid technologies for solar power generation. By converting sunlight into thermal emission tuned to energies directly above the photovoltaic bandgap using a hot absorber-emitter, solar thermophotovoltaics promise to leverage the benefits of both approaches: high efficiency, by harnessing the entire solar spectrum; scalability and compactness, because of their solid-state nature; and dispatchablility, owing to the ability to store energy using thermal or chemical means. However, efficient collection of sunlight in the absorber and spectral control in the emitter are particularly challenging at high operating temperatures. This drawback has limited previous experimental demonstrations of this approach to conversion efficiencies around or below 1% (refs 9, 10, 11). Here, we report on a full solar thermophotovoltaic device, which, thanks to the nanophotonic properties of the absorber-emitter surface, reaches experimental efficiencies of 3.2%. The device integrates a multiwalled carbon nanotube absorber and a one-dimensional Si/SiO2 photonic-crystal emitter on the same substrate, with the absorber-emitter areas optimized to tune the energy balance of the device. Our device is planar and compact and could become a viable option for high-performance solar thermophotovoltaic energy conversion.