Stars are born in clouds of hydrogen gas and dust called nebulae. Stars produce energy by nuclear fusion. Hydrogen gas atoms fuse together to form helium atoms. A lot of heat is produced in the fusion reaction which is emitted by the star. Large mass stars are very hot, and emit large amounts of heat but they have relatively short lifetimes.
Ada the science app explains the origin of all the elements in the Universe.