Large fractions of metals are missing from the observable gas-phase in the interstellar medium (ISM) because they are incorporated into dust grains. This phenomenon is called dust depletion. It is important to study the depletion of metals into dust grains in the ISM to investigate the origin and evolution of metals and cosmic dust. We characterize the dust depletion of several metals from the Milky Way to distant galaxies. We collected measurements of ISM metal column densities from absorption-line spectroscopy in the literature, and in addition, we determined Ti and Ni column densities from a sample of 70 damped Lyman-α absorbers (DLAs) toward quasars that were observed at high spectral resolution with the Very Large Telescope (VLT) Ultraviolet and Visual Echelle Spectrograph (UVES). We used relative ISM abundances to estimate the dust depletion of 18 metals (C, P, O, Cl, Kr, S, Ge, Mg, Si, Cu, Co, Mn, Cr, Ni, Al, Ti, Zn, and Fe) for different environments (the Milky Way, the Magellanic Clouds, and DLAs toward quasars and towards gamma-ray bursts). We observed overall linear relations between the depletion of each metal and the overall strength of the dust depletion, which we traced with the observed [Zn/Fe]. The slope of these dust depletion sequences correlates with the condensation temperature of the various elements, that is, the more refractory elements show steeper depletion sequences. In the neutral ISM of the Magellanic Clouds, small deviations from linearity are observed as an overabundance of the α-elements Ti, Mg, S, and an underabundance of Mn, including for metal-rich systems. The Ti, Mg, and Mn deviations completely disappear when we assume that all systems in our sample of OB stars observed toward the Magellanic Clouds have an α-element enhancement and Mn underabundance, regardless of their metallicity. This may imply that the Magellanic Clouds have recently been enriched in α-elements, potentially through recent bursts of star formation. We also observe an S overabundance in all local galaxies, which is an effect of ionization due to the contribution of their H ii regions to the measured S ii column densities. The observed strong correlations of the depletion sequences of the metals all the way from low-metallicity quasi-stellar object DLAs to the Milky Way suggest that cosmic dust has a common origin, regardless of the star formation history, which, in contrast, varies significantly between these different galaxies. This supports the importance of grain growth in the ISM as a significant process of dust production.