At the end of a normal-sized star's life, in the red giant phase, the outside layers of a star are ejected. Because the outside is gone, the star shines brightly and is very hot. The ultraviolet radiation given off by the center of the star ionizes the gas and plasma that was thrown out from the star. This is what causes a planetary nebula to look like it does.