H2O is not an element, it is a compound. ;-)
The first elements formed were Hydrogen, Helium, and Lithium as the early universe expended through temperatures and densities that were roughtly equivalent to the core of a star. The other elements had to wait a few million years for stars to form and start fusing Hydrogen into Helium, and then into Carbon and Oxygen in their cores. Then those stars had to explode as supernovae in order to spread those elements far and wide. Once those elements cooled gravity gradually drew them together and they formed clouds. And then molecules like water could form.