The Lyman decrement associated with the cumulative effect of H I in QSO absorption systems along the line of sight provides a distinctive feature for identifying galaxies at z greater than or similar to 2.5. Colour criteria, which are sensitive to the presence of a Lyman continuum break superposed oil an otherwise flat UV spectrum, have been shown, through Keck spectroscopy, to successfully identify a substantial population of star-forming galaxies at 3 less than or similar to z less than or similar to 3.5. Such objects have proven to be surprisingly elusive in field galaxy redshift surveys; quantification of their surface densities and morphologies is crucial for determining how and when galaxies formed. The Hubble Deep Field (HDF) observations offer the opportunity to exploit the ubiquitous effect of intergalactic absorption and obtain useful statistical constraints on the redshift distribution of galaxies to considerably fainter limits than the current spectroscopic limits. We model the H I cosmic opacity as a function of redshift, including scattering in resonant lines of the Lyman series and Lyman continuum absorption, and use stellar population synthesis models with a wide variety of ages, metallicities, dust contents and redshifts to derive colour selection criteria that provide a robust separation between high-redshift and low-redshift galaxies. From the HDF images we construct a sample of star-forming galaxies at 2 less than or similar to z less than or similar to 4.5. While none of the similar to 60 objects in the HDF having known Keck/Low-Resolution Imaging Spectrograph (LRIS) spectroscopic redshifts in the range 0 less than or similar to z less than or similar to 1.4 is found to contaminate our high-redshift sample, our colour criteria are able to efficiently select the 2.6 less than or similar to z less than or similar to 3.2 galaxies identified by Steidel et al. The ultraviolet (and blue) dropout technique opens up the possibility of investigating cosmic star and element formation in the early Universe. We set a lower limit to the ejection rate of heavy elements per unit comoving volume from Type II supernovae at [z]=2.75 of approximate to 3.6 x 10(-4) M. yr(-1) Mpc(-3) (for q(0)=0.5 and H-0=50 km s(-1) Mpc(-1)), which is 3 times higher than the local value but still 4 times lower than the rate observed at z approximate to 1. At [z]=4, our lower limit to the cosmic metal ejection rate is approximate to 3 times lower than the [z]=2.75 value. We discuss the implications of these results on models of galaxy formation, and on the chemical enrichment and ionization history of the intergalactic medium.