Background The human leukocyte antigen (HLA) isa highly polymorphic region, and HLA diversity may play a role in presenting tumour-associated peptides and inducing immune responses. However, the effect of HLA diversity on cancers has not been fully assessed. We aimed to explore the role of HLA diversity on cancer development. Methods A pan-cancer analysis was performed to evaluate the effect of HLA diversity, measured by HLA heterozygosity and HLA evolutionary divergence (HED), on the susceptibility of 25 cancers in the UK Biobank. Findings We observed that the diversity of HLA class II locus was associated with a lower risk of lung cancer (ORhetero = 0.94, 95% CI = 0.90-0.97, P = 1.29 x 10-4) and head and neck cancer (ORhetero = 0.91, 95% CI = 0.86-0.96, P = 1.56 x 10-3). Besides, a lower risk of non-Hodgkin lymphoma was associated with an increased diversity of HLA class I (ORhetero= 0.92, 95% CI = 0.87-0.98, P = 8.38 x 10-3) and class II locus (ORhetero= 0.89, 95% CI = 0.86-0.92, P = 1.65 x 10-10). A lower risk of Hodgkin lymphoma was associated with the HLA class I diversity (ORhetero = 0.85, 95% CI = 0.75-0.96, P = 0.011). The protective effect of HLA diversity was mainly observed in pathological subtypes with higher tumour mutation burden, such as lung squamous cell carcinoma (P = 9.39 x 10-3) and diffuse large B cell lymphoma (Pelass I = 4.12 x 10-4; Pelass II = 4.71 x 10-5), as well as the smoking subgroups of lung cancer (P = 7.45 x 10-5) and head and neck cancer (P = 4.55 x 10-3). Interpretation We provided a systematic insight into the effect of HLA diversity on cancers, which might help to understand the etiological role of HLA on cancer development. 2023;92: Published ohttps://doi.org/10. 1016/j.ebiom.2023. 104588