Exposure to UV rays, whether from sunlight or tanning devices, is a risk factor for all types of skin cancer. The risk is higher for people with a weakened immune system, a personal or family history of skin cancer, and if they have large or many moles on their skin.