Stars begin to form from clouds of gas in space. The cold temperatures and high densities (compared to elsewhere in space, but would be considered a vacuum on Earth) of these clouds allow gravity to overcome thermal pressure and start the gravitational collapse that will form a star.
A protostar looks like a star but its core is not yet hot enough for fusion to take place. The luminosity comes exclusively from the heating of the protostar as it contracts. Protostars are usually surrounded by dust, which blocks the light that they emit, so they are difficult to observe in the visible spectrum.

An artists rendition of the birth of a star. Credit: NASA/JPL-Caltech/R. Hurt
Sometimes the formation of stars can be encouraged or sped up by disturbances in the gas clouds that compress the gas such as other nearby stars or supernovae.
As the cloud collapses, it begins to spin and by the time a protostar is formed, the cloud flattens and there is a protostellar disk spinning around the protostar. These disks probably slow the rotation of the protostar, and sometimes coalesce into planetary systems.
As the protostar rotates, it generates a strong magnetic field. The magnetic field also generates a strong protostellar wind, which is an outward flow of particles into space. Many protostars also send out high-speed streams or jets of gas into space. Usually there are two jets flowing out along the rotation axis of the protostar. Eventually the wind and the jets clear away the extra gas around the protostar and allow the protostar to come into view.
A protostar becomes a main sequence star when its core temperature exceeds 10 million K. This is the temperature needed for hydrogen fusion to operate efficiently.
The length of time all of this takes depends on the mass of the star. The more massive the star, the faster everything happens. Collapse into a star like our Sun takes about 50 million years. The collapse of a very high mass protostar might take only a million years. Smaller stars can take more than a hundred million years to form.
