Transgender and nonbinary young adults in the United States (U.S.) experience disproportionately high rates of HIV and face unique barriers to accessing HIV testing, a key component of HIV prevention. Gender-affirming practices in healthcare settings may improve care access and reduce care avoidance among transgender and nonbinary people. To our knowledge, no study has examined the association between gender-affirming practices in healthcare settings and HIV testing among transgender and nonbinary U.S. young adults. This study analyzed national cross-sectional, online data from transgender and nonbinary U.S. young adults aged 18-30 years (N = 225) to assess the association between the gender affirmation sub-scale of the Transgender and Gender Diverse Healthcare Discrimination and Adverse Experiences Scale (range: 0-20) and past-year HIV testing using multivariable logistic regression. We found that a one-point increase in the gender affirmation sub-scale score was positively associated with past-year HIV testing (odds ratio = 1.15; 95% confidence interval: 1.06, 1.26), adjusting for age, geographic region, gender identity, educational attainment, employment status, having a usual source of care, and health insurance status. Our findings provide additional evidence that access to gender-affirming healthcare settings is important in facilitating utilization of preventive services among transgender and nonbinary U.S. young adults.