Emission nebulae are very often formed in the vicinity of young and hot stars. The energetic ultraviolet radiation of these stars excites the atoms of the surrounding gases to glow.
The color of the nebulae depends on both, the composition of the gas cloud and the energy of the radiation. Excited hydrogen, the main component of gas clouds, causes the reddish color. Other elements cause other colors, for example excited oxygen glows in bluish-green light.