Generally, you get HPV via oral or genital sex. There are two types of HPV high risk and low risk. The low risk types cause genital warts and generally don't cause cancer. The high risk can cause cancer but if you detect them early enough with a PAP smear then they won't develop into cancer. If you get the HPV vaccine it covers the most common high risk and low risk types but it doesn't cover all and you have to get it before you contract those types. If you are younger than 30 then you generally don't have to worry about the HPV test so much because you can rid your self of the HPV virus strains because you tend to shed vaginal and oral cells quickly. But after 30 cell regeneration slows down and the virus can hang on longer, giving it time to stay inside the cell. Again that is where regular PAP smears can help detect pre-cancerous cells.
hope this helps.
Thru genital skin to genital skin contact while having sex or intimacy. Condoms do not cover all of the genital skin such as thighs, scrotum, butt, base of penis, etc. It is un-avoidable if you are intimate.