ImportanceMental health among children and adolescents is a critical public health issue, and transgender and gender nonbinary youths are at an even greater risk. Social media has been consistently associated with youth mental health, but little is known about how gender identity interacts with this association.ObjectiveTo use a risk and resilience approach to examine the association between social media use and mental health among transgender, gender nonbinary, and cisgender youths.Design, Setting, and ParticipantsThis cross-sectional study analyzed data collected from an online survey between May and August 2021. Participants included a random sample of US youths; eligibility requirements included being aged 10 to 17 years and residing in the US. Statistical analysis was performed from February to April 2022.Main Outcomes and MeasuresSocial media use (time, type of use, favorite site, social comparisons, mindfulness, taking intentional breaks, cleaning and curating feeds, problematic use, and media literacy programs at their school) and mental health (depression, emotional problems, conduct problems, and body image) as main outcomes.ResultsParticipants included 1231 youths aged 10 to 17 years from a national quota sample from the United States; 675 (54.8%) identified as cisgender female, 479 (38.9%) as cisgender male, and 77 (6.3%) as transgender, gender nonbinary, or other; 4 (0.3%) identified as American Indian or Alaska Native, 111 (9.0%) as Asian, 185 (15.0%) as Black, 186 (15.1%) as Hispanic or Latinx, 1 (0.1%) as Pacific Islander, 703 (57.1%) as White, and 41 (3.3%) as mixed and/or another race or ethnicity. Gender identity moderated both the strength and the direction of multiple associations between social media practices and mental health: active social media use (eg, emotional problems: B = 1.82; 95% CI, 0.16 to 3.49; P = .03), cleaning and/or curating social media feeds (eg, depression: B = −0.91; 95% CI, −1.98 to −0.09; P = .03), and taking intentional breaks (eg, depression: B = 1.03; 95% CI, 0.14 to 1.92; P = .02).Conclusions and RelevanceIn this cross-sectional study of gender identity, social media, and mental health, gender identity was associated with youths’ experiences of social media in ways that may have distinct implications for mental health. These results suggest that research about social media effects on youths should attend to gender identity; directing children and adolescents to spend less time on social media may backfire for those transgender and gender nonbinary youths who are intentional about creating safe spaces on social media that may not exist in their offline world.