Let $\overline{\mathcal{M}}_{g,l}$ be the moduli space of stable algebraic curves of genus $g$ with $l$ marked points. With the operations that relate the different moduli spaces identifying marked points, the family $(\overline{\mathcal{M}}_{g,l})_{g,l}$ is a modular operad of projective smooth Deligne-Mumford stacks $\overline{\mathcal{M}}$ . In this paper, we prove that the modular operad of singular chains $S_*(\overline{\mathcal{M}}_{};\mathbb{Q})$ is formal, so it is weakly equivalent to the modular operad of its homology $H_*(\overline{\mathcal{M}}_{};\mathbb{Q})$ . As a consequence, the up-to-homotopy algebras of these two operads are the same. To obtain this result, we prove a formality theorem for operads analogous to the Deligne-Griffiths-Morgan-Sullivan formality theorem, the existence of minimal models of modular operads, and a characterization of formality for operads which shows that formality is independent of the ground field.