The direct detection of dark matter particles requires ultra-low background conditions at energies below a few tens of keV. Radioactive isotopes are produced via cosmogenic activation in detectors and other materials and those isotopes constitute a background source which has to be under control. In particular, tritium is specially relevant due to its decay properties (very low endpoint energy and long half-life) when induced in the detector medium, and because it can be generated in any material as a spallation product. Quantification of cosmogenic production of tritium is not straightforward, neither experimentally nor by calculations. In this work, a method for the calculation of production rates at sea level has been developed and applied to some of the materials typically used as targets in dark matter detectors (germanium, sodium iodide, argon and neon); it is based on a selected description of tritium production cross sections over the entire energy range of cosmic nucleons. Results have been compared to available data in the literature, either based on other calculations or from measurements. The obtained tritium production rates, ranging from a few tens to a few hundreds of nuclei per kg and per day at sea level, point to a significant contribution to the background in dark matter experiments, requiring the application of specific protocols for target material purification, material storing underground and limiting the time the detector is on surface during the building process in order to minimize the exposure to the most dangerous cosmic ray components.