CD4+ T cells orchestrate the adaptive immune response against pathogens and cancer by recognizing epitopes presented on MHC-II molecules. The high polymorphism of MHC-II genes represents an important hurdle towards accurate predictions of CD4+ T-cell epitopes in different individuals and different species. Here we generated and curated a dataset of 627,013 unique MHC-II ligands identified by mass spectrometry. This enabled us to determine the binding motifs of 88 MHC-II alleles across human, mouse, cattle and chicken. Analysis of these binding specificities combined with X-ray crystallography refined our understanding of the molecular determinants of MHC-II motifs and revealed a widespread reverse binding mode in MHC-II ligands. We then developed a machine learning framework to accurately predict binding specificities and ligands of any MHC-II allele. This tool improves and expands predictions of CD4+ T-cell epitopes, as demonstrated by the identification of several viral and bacterial epitopes following the aforementioned reverse binding mode.