One of the most important challenges in the field of electrodeposition in aqueous media concerns the synthesis of inorganic nanomaterials with excellent control of the film microstructure, morphology and crystallinity. In this work, we present a ground-breaking method for tailoring highly crystalline nanoporous layers of ZnO upon transparent conductive oxide substrates which extends the limit of electrodeposition in aqueous media. Being surfactant and template-free, the design of a well-defined ZnO nanostructure has been achieved by means of an accurate control of the electro-assisted generation of hydrogen bubbles which play the role of a ‘gas template’ enabling the formation of dense to highly porous ZnO mesostructures depending on H2 evolution. Such layers were successfully introduced in solid-state dye-sensitized solar cells. In combination with an organic D-π-A dye (C220) and CuSCN as hole transporter material, we achieved 2.1% power conversion efficiency.