Abstract Study question Do the genetic factors associated with idiopathic severe spermatogenic failure (SPGF) differ across age groups due to evolving environmental exposures over generations? Summary answer Dynamic changes in environmental exposures have the potential to reshape the genetic predisposition to idiopathic SPGF. What is known already Accumulating evidence suggests that the idiopathic form of SPGF may represent a complex trait with a multifactorial aetiology, wherein environmental factors influence the predisposition and development of the disease through their interaction with genetic polymorphisms. In a recent genome-wide association study (GWAS) of SPGF conducted in a European population, we identified genetic variants associated with this condition in immune and spermatogenesis-related genes. However, while GWASs serve as valuable tools for identifying susceptibility risk loci, our understanding of the influence of environmental factors and their specific impact on the genetic architecture of these conditions remains limited. Study design, size, duration Genome-wide genotype data from 912 SPGF cases and 1,360 unaffected controls from the Iberian Peninsula and Germany were analysed considering age as a proxy to assess exposure to varying environmental factors across generations. An in silico functional prioritisation of associated genomic regions was also performed to comprehensively evaluate the gene-environment relationships influencing the disease. Participants/materials, setting, methods The study cohort was stratified into two age groups: individuals aged 40 or older in 2023 (452 cases and 965 controls) and those under 40 in 2023 (460 cases and 424 controls). SPGF comprised individuals with non-obstructive azoospermia (n = 547) or non-obstructive oligozoospermia (n = 365). Logistic regression models were used for the case-control analysis, with the generation included as a covariate. Bioinformatic approaches involved the examination of functional annotations of the genome sourced from different public databases. Main results and the role of chance Thirteen genetic loci were found to be associated with idiopathic SPGF, assuming generation-dependent effects. Five of them showed a correlation with an increased susceptibility to SPGF in the youngest age group (rs72818509: P = 2.19E−05, rs57701320: P = 5.20E−05, rs79733930: P = 7.81E−05, rs77137582: P = 1.04E−04, rs75938373: P = 3.56E−05), while the remaining eight were specifically associated with the disease in the oldest age group (rs144324356: P = 2.37E−05, rs3763812: P = 8.61E−05, rs61997636: P = 1.00E−04, rs111364930: P = 9.63E−05, rs115408081: P = 5.77E-05, rs142908940: P = 1.76E−04, rs144031067: P = 1.76E-04, rs74514513: P = 1.76E-04). These associations were primarily attributed to the interaction between each lead variant and the age group. Additionally, associations were established between the identified genomic risk loci and various environmental factors, including toxic habits (such as smoking or alcohol consumption), diet-related traits (such as cholesterol levels, type 2 diabetes, and body mass index), respiratory disorders (such as asthma or COVID-19), autoimmune diseases (including systemic lupus erythematosus), and educational attainment. Our findings suggest that changes in environmental factors across generations could alter the genetic basis of idiopathic SPGF over time. Limitations, reasons for caution Despite the overall statistical power of our study cohort being suitable for detecting the expected effects, further independent studies comprising extensive cohorts across diverse ethnic populations are needed to validate the outcomes of our research. Wider implications of the findings Using a novel approach assess the potential impact of varying environmental factors on the genetic susceptibility to complex diseases, we gained insights into the intricate mechanisms underlying onset and progression of idiopathic SPGF. Understanding the etiological causes of multifactorial human disorders would help in developing personalized healthcare strategies. Trial registration number Not applicable