A star starts life in a nebula, a huge cloud of gas and dust that stretches over light-years. Nebulae are made up mostly of hydrogen (73.5%) and helium (24%), with small amounts of heavier elements, and are commonly known as "stellar nurseries." These clouds are dispersed until something disturbs them, like a supernova shockwave or a collision between galaxies, and they collapse under gravity. As parts of the nebula contract, they get fragmented into dense clumps, and each of these clumps will be a protostar.
A protostar is a hot, dense center surrounded by a disk of gas and dust. The inward movement of material causes the energy of gravity to be transformed into heat, raising the temperature of the protostar. This process typically lasts from 100,000 years to 10 million years based on the protostar's mass, and it is followed by the beginning of nuclear fusion. The protostar is still not an actual star, but its growing density paves the way for the subsequent stage. The process is nicely tumultuous, with jets of gas frequently being expelled from the poles of the protostar, sweeping away surplus material.