We study the evolution of the cold gas content of galaxies by splitting the interstellar medium into its atomic and molecular hydrogen components, using the galaxy formation model galform in the Λ cold dark matter framework. We calculate the molecular-to-atomic hydrogen mass ratio, H2/Hi, in each galaxy using two different approaches, the pressure-based empirical relation of Blitz & Rosolowsky and the theoretical model of Krumholz, McKeee & Tumlinson, and apply them to consistently calculate the star formation rates of galaxies. We find that the model based on the Blitz & Rosolowsky law predicts an Hi mass function, 12CO(1-0) luminosity function, correlations between H2/Hi and stellar and cold gas mass, and infrared-12CO molecule luminosity relation in good agreement with local and high-redshift observations. The Hi mass function evolves weakly with redshift, with the number density of high-mass galaxies decreasing with increasing redshift. In the case of the H2 mass function, the number density of massive galaxies increases strongly fromz= 0 to 2, followed by weak evolution up toz= 4. We also find that H2/Hi of galaxies is strongly dependent on stellar and cold gas mass, and also on redshift. The slopes of the correlations between H2/Hi and stellar and cold gas mass hardly evolve, but the normalization increases by up to two orders of magnitude fromz= 0 to 8. The strong evolution in the H2 mass function and H2/Hi is primarily due to the evolution in the sizes of galaxies and, secondarily, in the gas fractions. The predicted cosmic density evolution of Hi agrees with the observed evolution inferred from damped Lyα systems, and is always dominated by the Hi content of low- and intermediate-mass haloes. We find that previous theoretical studies have largely overestimated the redshift evolution of the global H2/Hi due to limited resolution. We predict a maximum of at z≈ 3.5. © 2011 The Authors Monthly Notices of the Royal Astronomical Society © 2011 RAS.