  We report measurements of the production of prompt D$^0$, D$^+$, D$^{*+}$ and
D$^+_{\rm s}$ mesons in Pb-Pb collisions at the centre-of-mass energy per
nucleon-nucleon pair $\sqrt{s_{\rm 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_{\rm T}$).
The $p_{\rm T}$ intervals covered in central collisions are: $1<p_{\rm T}<50$
Gev/$c$ for D$^0$, $2<p_{\rm T}<50$ GeV/$c$ for D$^+$, $3<p_{\rm T}<50$ GeV/$c$
for D$^{*+}$, and $4<p_{\rm T}<16$ GeV/$c$ for D$^+_{\rm s}$ mesons. The
nuclear modification factors ($R_{\rm AA}$) for non-strange D mesons (D$^0$,
D$^+$, D$^{*+}$) show minimum values of about 0.2 for $p_{\rm T}$ = 6-10
GeV/$c$ in the most central collisions and are compatible within uncertainties
with those measured at $\sqrt{s_{\rm NN}}=2.76$ TeV. For D$^+_{\rm s}$ mesons,
the values of $R_{\rm AA}$ are larger than those of non-strange D mesons, but
compatible within uncertainties. In central collisions the average $R_{\rm AA}$
of non-strange D mesons is compatible with that of charged particles for
$p_{\rm T} > 8$ GeV/$c$, while it is larger at lower $p_{\rm 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.
