ObjectivesUK National Health Service/Health and Social Care (NHS/HSC) data are variably shared between healthcare organisations for direct care, and increasingly de-identified for research. Few large-scale studies have examined public opinion on sharing, including of mental health (MH) versus physical health (PH) data. We measured data sharing preferences.Design/setting/interventions/outcomesPre-registered anonymous online survey, measuring expressed preferences, recruiting February to September 2020. Participants were randomised to one of three framing statements regarding MH versus PH data.ParticipantsOpen to all UK residents. Participants numbered 29 275; 40% had experienced an MH condition.ResultsMost (76%) supported identifiable data sharing for direct clinical care without explicit consent, but 20% opposed this. Preference for clinical/identifiable sharing decreased with geographical distance and was slightly less for MH than PH data, with small framing effects. Preference for research/de-identified data sharing without explicit consent showed the same small PH/MH and framing effects, plus greater preference for sharing structured data than de-identified free text. There was net support for research sharing to the NHS, academic institutions, and national research charities, net ambivalence about sharing to profit-making companies researching treatments, and net opposition to sharing to other companies (similar to sharing publicly). De-identified linkage to non-health data was generally supported, except to data held by private companies. We report demographic influences on preference. A majority (89%) supported a single NHS mechanism to choose uses of their data. Support for data sharing increased during COVID-19.ConclusionsSupport for healthcare data sharing for direct care without explicit consent is broad but not universal. There is net support for the sharing of de-identified data for research to the NHS, academia, and the charitable sector, but not the commercial sector. A single national NHS-hosted system for patients to control the use of their NHS data for clinical purposes and for research would have broad support.Trial registration numberISRCTN37444142.