Background. The role of HERV–H LTR-associating 2 (HHLA2) in cancer remains still unclear. This study analyzed the correlation between the prognosis and immune infiltrate function of HHLA2 in pan-cancers. Methods. HHLA2 expression in pan-cancers was analyzed using the databases of TCGA, GTEx, TIMER, GEPIA, UALCAN, and GSEA databases. Multiple bioinformatic methods were used to investigate the correlation of HHLA2 expression with survival, pathological stage, tumor mutation burden (TMB), microsatellite instability (MSI), tumor microenvironment (TME), immune cell infiltration, and immune checkpoint gene (ICG), and gene functional enrichment was performed by Gene Set Enrichment Analysis (GSEA) and Gene Set Variation Analysis (GSVA). Results. HHLA2 was aberrantly expressed and was strongly correlated with positive or negative prognosis in multiple human cancers, which revealed that HHLA2 might play a vital role during cancer formation and development. Kaplan–Meier (KM) curves across cancers revealed that HHLA2 expression was correlated with overall survival (OS) in eight cancers, disease-specific survival (DSS) in seven cancers, disease-free interval (DFI) in four cancers, and progression-free interval (PFI) in nine cancers. Furthermore, HHLA2 expression was positively correlated with TMB in 6 cancer types and negatively associated with TMB in 7 cancer types, respectively. The former included ESCA, HNSC, KIRP, PAAD, PRAD, and PCPG; the latter contained COAD, LGG, LUAD, LUSC, THYM, THCA, and UCEC. Additionally, we found HHLA2 expression was negatively related to MSI in ACC, COAD, PAAD, and UCEC. More importantly, HHLA2 expression was remarkably correlated with the degree of tumor-infiltrating immune in many cancers, including B cells, CD4+ T cells, CD8+ T cells, neutrophils, macrophages, and dendritic cells and strongly associated with immune checkpoint genes in 13 tumor types. Furthermore, KEGG pathway analyses indicated that HHLA2 could potentially impact cancer etiology or pathogenesis by functioning in amino sugar and nucleotide sugar metabolism, cytosolic DNA sensing pathway, and peroxisome pathways. Meanwhile, GSVA analysis results all indicate that HHLA2 was correlated with TSC/mTOR, RTK, RAS/MAPK, PI3K/AKT, EMT, DNA Damage Response, Cell Cycle, and Apoptosis pathways in various cancers. Conclusion. HHLA2 can function as a prognostic biomarker and correlate with tumor immunity in human pan-cancer due to its important role in tumorigenesis and immune infiltration, which provides new insight into developing new targeted treatments in cancers.