Stars are in a cloud of dust and gas, most of which was left when previous stars blew themselves apart in supernovae. The denser clumps of the cloud contract (very slowly) under the force of gravity.
When these clumps get dense enough, the cloud fragments into regions called protostars, that continue to contract and heat up.
Eventually the temperature at the centre of the protostar reaches a few million degrees, and hydrogen nuclei start to fuse together to form helium.
This releases an enormous amount of energy and creates enough pressure to stop the gravitational collapse.
The star has now reached the main sequence and will stay there, relatively unchanged, while it fuses hydrogen into helium.
Stars spend most of their lives as main sequence stars. The pressure produced from hydrogen fusion in their core balances the gravitational force trying to compress them. This stage is called core hydrogen burning.
When hydrogen in the core runs out nuclear fusion stops, and with it the outward pressure stops. The core contracts and heats up under the weight of the star.
The material surrounding the core still has plenty of hydrogen. The heat from the contracting core raises the temperature of this material enough for the hydrogen to fuse. This is called shell hydrogen burning.
The core continues to contract until, eventually, it gets hot enough and dense enough for helium to fuse into carbon and oxygen. This is called core helium burning. This releases a huge amount of energy, which pushes the outer layers of the star outwards. These outer layers cool, and the star becomes a red giant.
When the helium runs out, the carbon-oxygen core contracts again and heats a shell around it so that helium can fuse in this region. This is called shell helium burning.
In low-mass stars, the carbon-oxygen core isn’t hot enough for any further fusion and so it continues to contract under its own weight. Once the core has shrunk to about earth-size, electrons exert enough pressure to stop it collapsing any more.
The helium shell becomes more and more unstable as the core contracts. The star pulsates and ejects its outer layers into space as a planetary nebula, leaving behind the dense core.
The star is now a very hot, dense solid called a white dwarf, which will simply cool down and fade away.