The pH definition is the power/weight of hydrogen ions in a solution, expressed as a log function, as has been stated. Hydrogen ion is H+, hydroxide ion is OH-.
Absolutely pure water, nothing but H20, is in fact HOH (same as H2O, just written out to show it is in fact a hydrogen and hydroxide combined).
A tiny, tiny fraction of water is ionized into H+ and OH-, and as those ions are balanced (equal), the pH would be 7.0, neutral.
Allow that ultrapure water to have contact with the air and CO2 will dissolve and a tiny part of it will form carbonic acid, H2CO3. The pH will be pushed to the acid side, pH <7.0.
Carbonates and bicarbonates in solution form a buffer system, resisting change in the pH of the water. The crushed coral mentioned before provides carbonates/bicarbonates for the natural buffering system of water. Add some crushed coral to that acid ultrapure water and some will dissolve. The quantity of carbonate/bicarbonate will determine the pH of the water after soultion. It will no longer be ultrapure water.
So CO2 and carbonates/bicarbonates together control the pH of most natural waters (blackwater has organic acids as the primary controller), and are used as well in planted tanks. Very soft waters may gain stability by coral or aragonite addition, but they will gain GH (Ca++ and Mg++) as well.
HTH