We report measurements of the production of prompt D 0 , D + , D * + and D + s mesons in Pb-Pb collisions at the centre-of-mass energy per nucleon-nucleon pair √ s NN = 5.02 TeV, in the centrality classes 0-10%, 30-50% and 60-80%. The D-meson production yields are measured at mid-rapidity (|y| < 0.5) as a function of transverse momentum (p T). The p T intervals covered in central collisions are: 1 < p T < 50 GeV/c for D 0 , 2 < p T < 50 GeV/c for D + , 3 < p T < 50 GeV/c for D * + , and 4 < p T < 16 GeV/c for D + s mesons. The nuclear modification factors (R AA) for non-strange D mesons (D 0 , D + , D * +) show minimum values of about 0.2 for p T = 6-10 GeV/c in the most central collisions and are compatible within uncertainties with those measured at √ s NN = 2.76 TeV. For D + s mesons, the values of R AA are larger than those of non-strange D mesons, but compatible within uncertainties. In central collisions the average R AA of non-strange D mesons is compatible with that of charged particles for p T > 8 GeV/c, while it is larger at lower p T. The nuclear modification factors for strange and non-strange D mesons are also compared to theoretical models with different implementations of in-medium energy loss.