Stars are fossils that retain the history of their host galaxies. Carbon and heavier elements are created inside stars and are ejected when they die. Elements heavier than iron (such as gold) are also produced by neutron star mergers, although the contribution is very uncertain. Nonetheless, it is possible to constrain star formation and chemical enrichment histories of the galaxies from the spatial distribution of elements in galaxies. This approach, Galactic Archaeology, has been popularly used for our Milky Way Galaxy with a vast amount of data from Gaia and multi-object spectrographs. This approach can also be applied to external galaxies thanks to integral field units. For comparing to these observations, we have been running hydrodynamical simulations following detailed chemical enrichment from cosmological initial conditions. Metallicity is higher in more massive galaxies, and at the centre of galaxies. The mass--metallicity relations and radial metallicity gradients evolve at higher redshifts, and current observations indicate somewhat strong stellar feedback. Elemental abundances can put further constraints; the fluorine-enhanced galaxy at z=4.4 discovered by ALMA and the nitrogen emission of GN-z11 at z=10.6 taken by JWST/NIRSpec suggest enrichment from Wolf-Rayet stars, which becomes dominant during intermittent star formation in the very early universe.