Background Cross-sectional evidence suggests that living near green and blue spaces benefits mental health; longitudinal evidence is limited. Objectives To quantify the impact of changes in green and blue spaces on common mental health disorders, well-being and health service use. Design A retrospective, dynamic longitudinal panel study. Setting Wales, UK. Participants An e-cohort comprising 99,682,902 observations of 2,801,483 adults (≥ 16 years) registered with a general practice in Wales (2008–2019). A 5312-strong ‘National Survey for Wales (NSW) subgroup’ was surveyed on well-being and visits to green and blue spaces. Main outcome measures Common mental health disorders, general practice records; subjective well-being, Warwick–Edinburgh Mental Well-being Scale. Data sources Common mental health disorder and use of general practice services were extracted quarterly from the Welsh Longitudinal General Practice Dataset. Annual ambient greenness exposure, enhanced vegetation index and access to green and blue spaces (2018) from planning and satellite data. Data were linked within the Secure Anonymised Information Linkage Databank. Methods Multilevel regression models examined associations between exposure to green and blue spaces and common mental health disorders and use of general practice. For the National Survey for Wales subgroup, generalised linear models examined associations between exposure to green and blue spaces and subjective well-being and common mental health disorders. Results and conclusions Our longitudinal analyses found no evidence that changes in green and blue spaces through time impacted on common mental health disorders. However, time-aggregated exposure to green and blue spaces contrasting differences between people were associated with subsequent common mental health disorders. Similarly, our cross-sectional findings add to growing evidence that residential green and blue spaces and visits are associated with well-being benefits: Greater ambient greenness (+ 1 enhanced vegetation index) was associated with lower likelihood of subsequently seeking care for a common mental health disorder [adjusted odds ratio (AOR) 0.80, 95% confidence interval, (CI) 0.80 to 0.81] and with well-being with a U-shaped relationship [Warwick–Edinburgh Mental Well-being Scale; enhanced vegetation index beta (adjusted) –10.15, 95% CI –17.13 to −3.17; EVI2 beta (quadratic term; adj.) 12.49, 95% CI 3.02 to 21.97]. Those who used green and blue spaces for leisure reported better well-being, with diminishing extra benefit with increasing time (Warwick–Edinburgh Mental Well-being Scale: time outdoors (hours) beta 0.88, 95% CI 0.53 to 1.24, time outdoors2 beta −0.06, 95% CI −0.11 to −0.01) and had 4% lower odds of seeking help for common mental health disorders (AOR 0.96, 95% CI 0.93 to 0.99). Those in urban areas benefited most from greater access to green and blue spaces (AOR 0.89, 95% CI 0.89 to 0.89). Those in material deprivation benefited most from leisure time outdoors (until approximately four hours per week; Warwick–Edinburgh Mental Well-being Scale: time outdoors × in material deprivation: 1.41, 95% CI 0.39 to 2.43; time outdoors2 × in material deprivation −0.18, 95% CI −0.33 to −0.04) although well-being remained generally lower. Limitations Longitudinal analyses were restricted by high baseline levels and limited temporal variation in ambient greenness in Wales. Changes in access to green and blue spaces could not be captured annually due to technical issues with national-level planning datasets. Future work Further analyses could investigate mental health impacts in population subgroups potentially most sensitive to local changes in access to specific types of green and blue spaces. Deriving green and blue spaces changes from planning data is needed to overcome temporal uncertainties. Funding This project was funded by the National Institute for Health and Care Research (NIHR) Public Health Research programme (Project number 16/07/07) and will be published in full in Public Health Research; Vol. 11, No. 10. Sarah Rodgers is part-funded by the NIHR Applied Research Collaboration North West Coast. Plain language summary We investigated whether people who live near or visit green (parks, woodlands) and blue (riversides, beaches) spaces have fewer common mental health disorders (anxiety or depression), and better well-being. We considered whether changes in the amount of green and blue space around the home affected people’s mental health. We assessed the availability of local green and blue spaces. Annual exposure and access to local green and blue spaces were extracted from planning and satellite data. We linked these data to anonymised health records of 2,801,483 adults registered with a general practice from 2008 to 2019, and to survey answers about leisure visits to natural environments and well-being. We found: people who lived in greener and bluer areas were less likely to seek help for a common mental health disorder than those in less green or blue areas, with those living in the most deprived areas benefiting the most people who used green and blue spaces for leisure, especially those with the greatest levels of deprivation, had better well-being and were less likely to seek help for common mental health disorders no evidence that changing amounts of green and blue space affected how likely people were to seek help for common mental health disorders; this may be because we found mostly small changes in green and blue space, and we may not have allowed enough time between moving home and recording mental health. We found evidence for relationships between green and blue space and mental health. However, some analyses were restricted due to lack of data on changes in green and blue spaces. An important finding was that people in deprived communities appear to benefit the most. Provision of green and blue spaces could be a strategy to improve the mental health of people living in disadvantaged areas. Scientific summary Background Cross-sectional evidence suggests that living close to and spending time in and around green and blue spaces (GBS, e.g. parks, gardens, ponds, lakes, rivers) is associated with higher levels of well-being and fewer mental health problems. Some of these benefits could result from living near GBS; others (e.g. physical activity) are attributed to using GBS. There are few longitudinal studies examining whether changes in GBS affect subsequent mental health. Existing studies have largely had small cohorts, assessed change over a short time, did not investigate socioeconomic inequalities in effects and neglected to consider that some health benefits depend on using GBS rather than simple exposure. Objectives We examined the research questions: Is a greater residential exposure and access to GBS associated with the likelihood of seeking help for a common mental health disorder (CMD) in general practice? Is the association between exposure, or access to, GBS and seeking help for a CMD modified by socioeconomic disadvantage and moving home? Is a greater residential exposure associated with the likelihood of using general practice services? Is greater residential GBS exposure and access to GBS associated with higher subjective well-being or a lower likelihood of seeking help for CMD, and does intentional use of GBS for leisure mediate these associations? Are associations between residential GBS exposure and access to GBS and use and subjective well-being mediated by walking-specific physical activity and modified by socioeconomic disadvantage? Methods We used a dynamic longitudinal panel study design to retrospectively examine natural and non-random variation in GBS exposure during an 11-year period, with individual linkage to survey responses. Data sources We constructed an electronic cohort of the population of Wales using data from the Welsh Demographic Service Dataset. Household-level ambient greenness was determined from satellite imagery, access to GBS from planning records, CMD and service use from Welsh Longitudinal General Practice Dataset (WLGPD) and for a subgroup, well-being and behaviour responses to the National Survey for Wales (NSW, 2016/17 and 2018/19). Data are held in the Secure Anonymised Information Linkage (SAIL) databank. Inclusion criteria The cohort included everyone aged 16 years and over registered with a general practitioner (GP) providing patient records to the SAIL databank between January 2008 and October 2019 (‘the study period’). Those not registered with an appropriate GP, not having a Welsh residential address between January 2008 and October 2019, and not having sex/week of birth recorded were excluded from the study sample. Exposures Our primary environmental exposure was ambient greenness, measured yearly (2008–19) by mean enhanced vegetation index (EVI) averaged over a 300 m circular buffer centred on each residence. Our secondary environmental exposure was the potential for an individual to access GBS along paths/roads within 1600 m of each home, modelled for 2018. We captured changes only when individuals moved home. For research questions 1–3, GBS access was quantified by the number of potentially accessible GBS. For research questions 4–5, access was quantified as the proximity to the nearest GBS. Outcome measures For research questions 1–3, our primary outcome was seeking help for CMD in general practice, identified from practice records using a validated algorithm. Our secondary outcome was the quarterly count of general practice events. For research questions 4 and 5, our primary outcome was subjective well-being, measured by the Warwick–Edinburgh Mental Well-being Scale (WEMWBS) in the NSW. Secondary outcomes were life satisfaction (NSW) and seeking help for CMD in general practice. Self-reported time outdoors on recreational visits to GBS in Wales and walking-specific physical activity were identified (NSW). Statistical analysis Research questions 1–3 were addressed using complementary approaches: We first evaluated associations between cumulative EVI exposure and seeking help for CMD in general practice using multivariate logistic regression. Follow-up stopped when help was first sought for CMD or at the end of the study period. This time aggregated design allowed us to consider environmental exposure prior to seeking help for CMD in general practice and included differences between people. We conducted stratified analyses according to area-level deprivation (Welsh Index of Multiple Deprivation, WIMD) quintiles, home moves (none/one/more than one), history of seeking care for CMD in general practice (before January 2008) and urban-rural home location. Next, we assessed associations between longitudinal change in GBS exposures for the same individuals, and their subsequent likelihood of seeking help for CMD (primary outcome) using multivariate logistic regression. For the association with general practice services use (secondary outcome) we used Poisson regression. We used a panel design with a multilevel model structure (quarterly observations nested within individuals). We accounted for clustering of observations over time (using random effects), and unbalanced data (number of observations varying for individuals). Change in GBS exposure was modelled as a continuous variable relative to previous time periods. For people who did not move home, we modelled EVI change categories to examine in situ exposure changes. Stratified analyses were conducted for quintiles of WIMD and number of home moves. For research questions 4–5 we assessed whether GBS exposures were related to WEMWBS, life satisfaction and seeking help for CMD, and whether there was moderation by socioeconomic disadvantage. We examined whether the association between GBS exposures and WEMWBS, life satisfaction and seeking help for CMD, were mediated by time spent outdoors. Generalised additive models were used to identify any non-linear associations and inform subsequent generalised linear regression. When predicting WEMWBS, linear and quadratic terms for EVI were included and proximity to nearest GBS was categorised. For seeking help for CMD, EVI was categorised, and proximity was continuous. To assess moderation by socioeconomic disadvantage, we included interactions between material deprivation and the GBS exposures. Results The cohort included 2,801,483 individuals (99,682,902 observations). A total of 816,242 individuals (29.1%) sought help for CMD from their general practice at least once in the study period. Research question 1: Is a greater residential exposure and access to GBS associated with the likelihood of seeking health for CMDs in general practice? People who lived in homes surrounded by more ambient greenness (+ 0.1 EVI) were associated with 20% lower odds of seeking help for CMD in general practice [adjusted odds ratio (AOR) 0.80, 95% confidence interval (CI) 0.80 to 0.81]. More potentially accessible GBS (equivalent to 236 more GBS) were associated with 7% lower odds of seeking help for CMD (AOR 0.93, 95% CI 0.93 to 0.93). Every additional 360 m (0.1 unit) to the nearest GBS was associated with 5% higher odds of seeking help for CMD (AOR 1.05, 95% CI 1.04 to 1.05). People experiencing an increase of 0.1 mean EVI was not associated with seeking help for CMD in general practice (exposure change relative to: previous quarter/year/baseline AOR 1.00, 95% CI 1.00 to 1.00). Among the 1,611,581 people who did not move home (57.5% of the cohort), increases or decreases of ≥ 0.15 EVI relative to baseline were not associated with seeking help for CMD (AOR for ≥ +0.15 EVI 1.00, 95% CI 0.99 to 1.00; AOR for ≥ −0.15 EVI 1.00, 95% CI 1.00 to 1.01). Among those who moved home at least once, an increase in the number of potentially accessible GBS was not associated with seeking help for CMD in general practice (GBS increase relative to previous quarter/year/baseline: AOR 1.00, 95% CI 1.00 to 1.00). Research question 2: Is the association between exposure, or access to, GBS and seeking help for a CMD modified by socioeconomic disadvantage and moving home? Living in a home with greater EVI (+ 0.1) and more accessible GBS (+ 236) was associated with lower odds of seeking help for CMD in general practice in all deprivation quintiles and whether people moved. The odds of seeking help were lower for those who did not move (AOR non-movers 0.77, 95% CI 0.77 to 0.78; AOR moved > once 0.92, 95% CI 0.91 to 0.93). There was no evidence that EVI or GBS changes were associated with seeking help for a CMD for people living in either the most or least deprived urban areas. An increase of 0.1 mean EVI (relative to baseline) was associated with slightly lower odds of seeking help for CMD for people who moved home more than once (AOR 0.99, 95% CI 0.99 to 0.99) but not for those who moved once or had not moved. Association between different GBS exposures and seeking help for CMD in general practice were modified by urban–rural home location and a history of seeking help for CMD. Greater EVI was associated with lower odds of seeking help for a CMD for those living in rural areas (AOR 0.59, 95% CI 0.58 to 0.59) compared with urban areas (AOR 0.85, 95% CI 0.84 to 0.85). More potentially accessible GBS were only associated with lower odds of seeking help for CMD for those living in urban areas (AOR 0.89, 95% CI 0.89 to 0.89). In rural areas more GBS access was associated with higher odds of seeking help for CMD (AOR 1.10, 95% CI 1.08 to 1.12). More ambient greenness (+ 0.1 EVI) was associated with lower odds of seeking help for a CMD for those who had historically sought help for CMD (before January 2008) than people who had not (AOR 0.68 vs. 0.84). Research question 3: Is a greater residential exposure associated with the likelihood of using GP services? There was no evidence that an increase in mean EVI was associated with the number of general practice event days/quarter (adjusted incidence rate ratio relative to baseline: 1.00, 95% CI 1.00 to 1.00). Research question 4: Is greater residential GBS exposure and access to GBS associated with higher subjective well-being, or a lower likelihood of seeking help for CMD in general practice, and are these associations mediated by intentional use of GBS for leisure? Among NSW respondents with outcome measures (n = 5971) EVI was significantly related to well-being as measured by WEMWBS with a U-shaped relationship (linear regression; EVI −10.15, 95% CI −17.13 to −3.17; EVI2 12.49, 95% CI 3.02 to 21.97) and weekly time outdoors (linear relationship; EVI 43.41, 95% CI 6.85 to 79.97). Time outdoors was significantly positively related to WEMWBS [time outdoors (hours) 0.88, 95% CI 0.53 to 1.24, time outdoors (hours)2 −0.06, 95% CI −0.11 to −0.01] and life satisfaction [linear relationship; time outdoors (hours) 0.06, 95% CI 0.04 to 0.07]. There was no evidence that time outdoors mediated the relationship between EVI and WEMWBS/life satisfaction. EVI was not associated with CMD (EVI 0.4 to 0.8 vs.