PurposeThis study aims to explore the Facebook communication strategies of Spanish hospitals during health emergencies, focusing on their role in crisis management and public information dissemination.Design/methodology/approachAutomatic topic modelling and deep learning sentiment analysis were applied to analyse 151,738 posts from 274 hospital Facebook pages (March 2020–Feb 2022). Regression analyses were used to explore the relationships between topics, sentiment scores and hospital characteristics.FindingsThe analysis revealed nine main topics, with the three most prevalent related to COVID-19: vaccine information, security measures and situational updates. This indicates that Spanish hospitals significantly relied on Facebook to manage the emergency. The communication strategies dynamically adapted to the intensity of the pandemic and varied across hospital types. Sentiment analysis showed a negative tone for posts about security measures and situational updates. These findings align with the Agenda-Setting Theory, suggesting that hospitals influenced public discourse. Vaccine information posts were more positive, resonating with the Uses and Gratifications Theory by fulfilling the audience’s need for reassurance and guidance.Originality/valueUsing replicable machine learning techniques, this study elucidates the communication strategies employed by Spanish hospitals to manage healthcare emergencies, such as the COVID-19 pandemic. It highlights factors that potentially influence these strategies and provides theoretical justifications for them. The variation in communication strategies on Facebook among different hospital categories underscores the imperative for stricter guidelines and regulations to guarantee consistent and reliable communication during emergencies. This research provides valuable insights for practitioners and policymakers aimed at developing effective health communication strategies on social media.