The distribution of human papillomaviruses (HPVs) must be understood for the control and prevention of cervical cancer. Community-based Papanicolaou and HPV DNA tests were performed on 41 578 women. The prevalences of HPV genotypes 16, 18, 31, 33, 35, 39, 45, 51, 52, 56, 58, 59, 66 and 68 were assessed. In total, 10% women were infected/co-infected by these HPVs. The infection rate increased from 7.1% in women aged ⩽30 years to 10.4% in those aged 50–60 years, and then decreased slightly to 9.9% in those aged >60 years. The HPV 16 and 58 positivity rates were significantly higher among women with high-grade squamous intraepithelial lesions (HSILs) than among those with cervicitis/negativity for intraepithelial lesion or malignancy (NILM) or low-grade SILs (LSILs). The HPV 18, 52 and 68 infection rates were significantly lower in women with HSILs than in those with NILM or LSILs. The proportion of women infected by multiple HPV strains was higher among those with HSILs. The proportions of the five most common genotypes, HPV 16, 18, 33, 52 and 58, increased with the number of co-infecting strains. HPV 16 and 58 were the high-risk HPVs in the Shanghai community and should be the focus in HPV screening and vaccination.