The evolution of cosmic dust content and the cycle between metals and dust in the interstellar medium (ISM) play a fundamental role in galaxy evolution. The chemical enrichment of the Universe can be traced through the evolution of the dust-to-metal ratio (DTM) and the dust-to-gas ratio (DTG) with metallicity. The physical processes through which dust is created and eventually destroyed remain to be elucidated. We use a novel method to determine mass estimates of the DTM, DTG, and dust composition in terms of the fraction of dust mass contributed by element X (fMX) based on our previous measurements of the depletion of metals in different environments (the Milky Way, the Magellanic Clouds, and damped Lyman-α absorbers (DLAs) towards quasars (QSOs) and towards gamma-ray bursts (GRBs)), which were calculated from the relative abundances of metals in the ISM through absorption-line spectroscopy column densities observed mainly from VLT/UVES and X-shooter, and HST/STIS. We also derive the dust extinction from the estimated dust depletion (AV,depl) for GRB-DLAs, the Magellanic Clouds, and the Milky Way, and compare it with the AV estimated from extinction (AV,ext). We find that the DTM and DTG ratios increase with metallicity and with the dust tracer [Zn/Fe]. This suggests that grain growth in the ISM is the dominant process of dust production, at least in the metallicity range (−2 ≤ [M/H]tot ≤ 0.5) and redshift range (0.6 < z < 6.3) that we are studying. The increasing trend in the DTM and DTG with metallicity is in good agreement with a dust production and evolution hydrodynamical model. Our data suggest that the stellar dust yield is much lower (about 1%) than the metal yield and thus that the overall amount of dust in the warm neutral medium that is produced by stars is much lower than previously estimated. The global neutral gas metallicity is decreasing over cosmic time and is traced similarly by quasar-DLAs and GRB-DLAs. We find that, overall, AV,depl is lower than AV,ext for the Milky Way and in a few lines of sight for the Magellanic Clouds, a discrepancy that is likely related to the presence of carbonaceous dust associated with dense clumps of cold neutral gas. For the other environments studied here, we find good agreement overall between the AV,ext and AV,depl. We show that the main elements (fMX > 1%) that contribute to the dust composition, by mass, are O, Fe, Si, Mg, C, S, Ni, and Al for all the environments, with Si, Mg, and C being equivalent contributors. There are nevertheless variations in the dust composition depending on the overall amount of dust. The abundances measured at low dust regimes in quasar- and GRB-DLAs suggest the presence of pyroxene and metallic iron in dust. These results give important information on the dust and metal content of galaxies across cosmic times, from the Milky Way up to z = 6.3.