The answer to this question is quite a long one. Molecular clouds (sections of gasses and other elements) in the universe starts to join and clump due to gravity (the weakforce). once this clump of material becomes larger it posseses a higher gravitational force witch causes this cloud to collapse in on itself forming a plasma ball witch is the begining of a star. such as below. Once this ball is formed the forces inside start to react the hydrogen forming a nuclear reactor. Once all the hydrogen in the star is "burnt" if the star is big enough (bigger the star the faster it used the feul due to more gravational force and therefore shorter lifespan) and has enough internal force it will begin to use the helium and turn the now crabon core to iron but this process takes more energy cuasing the star to become cooler and glow more orange. Once everything is used up the star explodes into a supernova and once the supernova is finished the star will implode into a blackhole. Smaller stars such as our sun last a lot longer and when their life is over they simply get dimmer and cooler until there is no heat or light being emitted.
Gravity pulls the nebula for the stars and in that cloud dust they are born. They burn fuel for millions and billions and even trillions of years. Larger stars burn their fuel out faster. When they start to run out of fuel, the star turns dimmer and gets colder. It changes color and when it runs out of fuel, it explodes and turns into a supernova and if it misses its stage, it becomes a black hole.