The complex associations of socioeconomic status (SES) and lifestyle with dementia are unclear. Our objective was to examine whether a broad combination of lifestyle factors mediates the associations of SES with incident dementia and the extent of interaction or joint relations of lifestyles and SES with dementia. A total of 274,871 participants from the UK Biobank were included. SES was assessed using the Townsend Deprivation Index. A lifestyle index was created based on smoking status, alcohol consumption, physical activity, social connections, sleep duration, diet, and sedentary behavior. Cox proportional hazards models were fitted. Mediation and interaction analyses were conducted to explore the relationship between lifestyles and SES in dementia. The HRs (95% CIs) for when participants with low SES were compared with participants of high SES were 1.32 (1.22-1.42) for all-cause dementia, 1.25 (1.11-1.40) for Alzheimer's disease (AD), and 1.61 (1.37-1.90) for vascular dementia (VD). Lifestyles explained ≤ 7.8% of socioeconomic disparities in dementia. Unhealthy lifestyle categories were associated with a higher risk of dementia and its subtypes across all SES levels. The HRs (95% CIs) for all-cause dementia, AD, and VD comparing participants with low SES and the least healthy lifestyle versus those with high SES and the healthiest lifestyle were 1.82 (1.56-2.11), 1.51 (1.20-1.90), and 2.56 (1.81-3.61), respectively. Adhering to a healthy lifestyle may prevent dementia across all socioeconomic groups, but socioeconomic inequalities in dementia cannot be fully addressed by promoting healthy lifestyles alone. The social determinants of dementia need to be better addressed.