The Universe is mostly empty - not empty as in an empty room (which is full of air) but empty as in there is nothing there at all (a vacuum). I say mostly empty beacause the is a bit of stuff there: hydrogen. But not very much, about 1 million particles in every cubic meter. In some parts of the universe the density of hydrogen is a bit better (1 billion particle per cubic metre) and this is enough for gravitational attraction to have an effect: all of the particles drift together and form a dense cloud. Once this cloud reaches a particular size it takes on a life of its own and begins to attract more and more particles. It becomes mose dense and begins to heat up (but not very much, only about 10K or 10°C).
This massive cloud gets a bit unstable and tends to break up leaving lots of little dense clouds. Each of these little clouds (each bigger than our solar system) can now contract in relative peace, getting hotter and more dense until it forms a protostar. This protostar is still only a hot ball of gas - it needs a tirgger to turn it into a bona fide astral body.
This trigger is gravity which compresses the cloud more and more until the hyrogen atoms in the centre are crushed together. Once the star is good and hot, and the internal temperature and pressure are high enough, hydrogen atoms begin to fuse together to form heluim. The released energy from this nuclear reaction set off more fusions and a chain reaction is started - the protostar now has a self sustaining core and can truly be called a star.
Not all of the hydrogen gas in the interstellar cloud was used in the formation of the star. There is a lot left over. One of the intrinsic properties of stars is that they rotate. This rotation of the star drags all the leftover gas around until a thin disc is formed. Although not very dense there is enough material for the spinning motion causes the particles to bang into one another.
Every now and then, a couple of particles will collide and stick together. They become a bigger target for other particles and very slowly lumps start to appear. As the lumps get bigger, they will coagulate (join up) and before you know it you have a proto-planet. Things really speed up now as the proto-planets sweep up all of the remaining particles in the disc and the system settles down. Each of the planets is a mix of ice, gas, dust and other debris that needs to get sorted out. Because of gravity all the heavier bits sink towards the centre leaving the lighter molecules to hang around on the surface. This layering process allows the gasses to be 'blown away' by the star as its heat burns way the lighter elements (mainly hydrogen and helium). The further out from the sun you arew, the colder it gets so the outer planets tend to pick up these loose elements. If you consider our solar system this is exactly what we have: hot rocky planets near the Sun and cold gaseous ones further out.
So now we have a number of planets orbiting majestically around a star that is merrily converting hydrogen into helium and other elements.
What happens next? There comes a point when there is no more hydrogen left to burn in the core of the star and the core collapses. This heats things up again and ignites the helium that had been surrounding the core. And guess what, all the helium will eventually be burnt off, the shell collapses, heats up and ignites the next layer and so on until the remains completely collapse. This process is the source of all the elements up to Iron (atomic number 56).
The story of the star from now on depends very much on how big it is. In general, the bigger the star the shorter its lifetime.
The diagram above, the Hertzsprung-Russell diagram, shows the four main groupings of stars. Most stars sit on the main sequence. The Sun is the yellow dot in the middle.
As the bigger stars burn out they leave the main sequence and swell to become red giants or supergiants. These are, as their name suggests, massive stars. They have a very high core temperature and are much brighter with a huge surrounding dust shells which is why they look so spectacular. They are the source of just about all the heavy elements in the universe. In fact the nuclear processes leave behind an iron core which, as the star continues to burn, can no longer support the star. The core collapses producing a rapid increase in temperature and a shock wave races out from the centre. This shock wave meets the outer layers which are trying to collapse and the star explodes: a supernova. There are two type of supernoave. Type I are the really big stars, and are usually older. Type II are younger, faster evolving stars. Supernova are the source of all elements above Atomic Number 56 (Iron).
Stars like the Sun simply cool down and shrink to the size of the Earth, emitting white or blue-white light and forming the group called White Dwarves.