By means of detailed chemo-photometric models for elliptical, spiral and irregular galaxies, we evaluate the cosmic history of the production of chemical elements as well as the metal mass density of the present-day Universe. In particular, we study the production rates of some of the most common chemical species (O, Mg, N, Si, Fe and Zn), detected in local stars, Galactic and extragalactic H II regions and high-redshift objects. Such a study allows us to compute in detail the fraction of each element locked up in stars, interstellar gas and intergalactic medium. We then calculate the mean metal abundances for galaxies of different morphological types, along with the average metallicity of galactic matter in the Universe (stars, gas and intergalactic medium). For the average metallicity of galaxies in the local Universe, we find <Z> (gal) = 0.0175, i.e. close to the solar value. We find the main metal production in spheroids (ellipticals and bulges) to occur at very early times, implying an early peak in the metal production and a subsequent decrease. On the other hand, the metal production in spirals and irregulars is always increasing with time. We find that the average [O/Fe](*), E ratio in stars in spheroids should be +0.4 dex, whereas the average [O/Fe](gas,) (E) ratio in the gas should be -0.33 dex, as a result of the large amount of Fe produced in these systems by Type Ia supernovae after star formation has stopped. The same quantities for spirals are similar to +0.1 dex for the stellar component and almost solar (similar to +0.01 dex) for the gas component. We suggest that a Salpeter-like initial mass function (IMF) is the best candidate for the universal IMF because it allows us to reproduce the majority of observational constraints. We perform a self-consistent census of the baryons and metals in the local Universe finding that, while the vast majority of the baryons lie outside galaxies in the intergalactic medium (IGM), 52 per cent of the metals (with the exception of the Fe-peak elements) are locked up in stars and the interstellar medium. We estimate indirectly the amount of baryons that resides in the IGM and derive its mean Fe abundance, finding a value of X-Fe,X- IGM = 0.05 X (Fe,).. We believe that this estimate is uncertain by a factor of similar to2, owing to the normalization of the local luminosity function. This means that the Fe abundance of 0.3 solar inferred from X-ray observations of the hot intracluster medium (ICM) is higher than the average Fe abundance of the intergalactic gas in the field.