Far out in space, the comets tail is short. As it approaches the Sun, the heat melts away some of the ice covering the surface. As it evaporates into space. a tail is formed behind the comet. Always, the tail is facing away from the sun.
Hope this helped. Have a great day! :D