Comets spend most of their time far away from the sun, in the very cold outer reaches of the solar system, only coming in close to the sun every few thousand or even every few million years.
Comets are most easily visible when they get close to the sun, and the many different types of ices on their surfaces start to sublimate (turn from solid into gas).  This makes the comet turn from a small, dark rock into a huge, puffy cloud of gas and dust, making it much easier to see with telescopes or sometimes even with just your eyes.  As the comet gets warmer, it grows a tail of gas and dust that can be millions of miles long, always pointing away from the sun.