Actually when they are far away from the sun the comets are icy,cold objects.this is calls the nucleus of it.When the near the sun it warms up and the mixture of gases give it the tail..
1 4 1
Most comets are made of frozen ice and dust particles. Comets spend the majority of their time far from the Sun. Because of their long, highly elliptical orbits ,the long period comets will eventually approach the Sun, increasing in velocity rapidly as they do. The ice and dust begin to melt forming a "cloud" around the nucleus of the comet. This cloud is pushed away from the direction of the Sun by two forces, the solar wind - particles of charged gas streaming out from the Sun, and light pressure - the force generated from packets of energy known as quanta or photons that is a property of light energy. 

This actually generates two tails: an ion tail of comet gases caused by the solar wind and a slightly curved dust tail generated by the photons striking the comet's suspended dust particles. 
1 3 1