Purpose This study was conducted to evaluate the status of depression and anxiety of healthcare workers and to explore the risk factors during the outbreak of COVID-19 in China. Methods A cross-sectional study was designed using convenience sampling to obtain a sample of healthcare workers. A structured questionnaire was designed to collect the information of the basic characteristics, workload, and the health condition. Burnout, coping style, anxiety, and depression were measured by specific scales. Multiple logistic regression model was performed to explore the risk factors of anxiety or depression. Results There were 902 questionnaires received between February 9, 2020 and February 11, 2020. The proportion of healthcare workers with symptoms of moderate/severe anxiety and moderate/severe depression were 16.63% and 18.29%, respectively. There were 24.50% healthcare workers experiencing moderate/severe anxiety and depression at the same time. The increased workload, respiratory symptoms, digestive symptoms, having done specific test(s) related to COVID-19, having family member needs to be taken care of, negative coping style, and job burnout were the independent risk factors of anxiety. Furthermore, the increased workload, respiratory symptoms, digestive symptoms, having done specific test(s) related to COVID-19, negative coping style, and job burnout were the independent risk factors of depression. Conclusion More attention should be paid to the mental health of frontline healthcare workers at the outbreak of COVID-19 in China. Taking steps to reduce the intensity of the work and burnout will be effective to stabilize the mental state of them. Electronic supplementary material The online version of this article (10.1007/s00127-020-01954-1) contains supplementary material, which is available to authorized users.