Hydrogen is a carrier of energy, not a source. In most cases in our world today, it’s made by electrolyzing water, i.e., breaking down the H2O molecule to its component gases, using electricity from the grid. Since most of our grid energy derives from the consumption of fossil fuels that has negative effects on the environment, efforts are big taken to replace them with low-carbon sources, e.g., renewables and nuclear.
As discussed here, green hydrogen, or hydrogen created from electrolyzing water with low-carbon power, will likely be an important component of our energy mix as we enter the middle part of the 21st Century.
True, the processes by which hydrogen is made and consumed (through fuel cells) have low efficiencies; in total, only about half of the energy going in is ultimately available for use. But hydrogen is portable, making it ideal for the transportation sector that consists of large, heavy vehicles: ocean-going cargo ships, aircraft, and Class 8 trucks.
Storing energy in batteries and discharging them through motors is a far more efficient undertaking, but will battery technology improve to the point it becomes feasible for these purposes, and hydrogen becomes obsolete? It’s possible, but it’s good to know that hydrogen represents a solid solution if required.