The gravitational contraction is resisted by thermal pressure , rotation , and magnetic fields . Ignoring rotation and magnetic fields, the evolution of a contracting clump of molecular gas proceeds as follows. The cloud is at first relatively transparent to photons and is able to radiate away all the gravitational energy released in the contraction. Because the temperature therefore does not rise but the gravity increases, smaller portions of the cloud can collapse and the cloud fragments . As the density of the individual fragments climbs higher, they eventually become opaque to photons and start to heat up.
Fragmentation then ceases.
As the density and temperature increase, the fragment eventually becomes spherical due to the increasing gravitational field. The protostar glows in the red as the photosphere temperature reaches several thousand degrees, and because it is huge in size, the total luminosity is enormous. At this stage the protostar is in the upper right of the HR diagram. Subsequent evolution of the protostar takes it to the main sequence along a path which depends on the protostar's mass. High mass protostars evolve horizontally on the HR diagram towards the upper main sequence, while low mass protostars evolve vertically down towards the lower main sequence.