Enhancing awareness and use of pre-exposure prophylaxis (PrEP) and post-exposure prophylaxis (PEP) is vital to curb human immunodeficiency virus (HIV) spread. High-risk behaviors prevalent among sexually transmitted infection clinic outpatients underscore the need for increased PrEP/PEP education in this group. To investigate the effects of both onsite and online health education on the knowledge of, and willingness to use, PrEP and PEP among individuals receiving PEP services. Participants were drawn from a cohort study on PEP service intervention at an STD/AIDS outpatient clinic in designated HIV/AIDS hospitals in Beijing, conducted from January 1 to June 30, 2022. Health education was provided both onsite and online during follow-up. Surveys assessing knowledge of, and willingness to use, PrEP/PEP were administered at baseline and again at 24 wk post-intervention. A total of 112 participants were enrolled in the study; 105 completed the follow-up at week 24. The percentage of participants with adequate knowledge of, and willingness to use, PrEP significantly increased from 65.2% and 69.6% at baseline to 83.8% and 82.9% at the end of the intervention (both P < 0.05). Similarly, those with adequate knowledge of, and willingness to use, PEP increased from 74.1% and 77.7% at baseline to 92.4% and 89.5% at week 24 (P < 0.05). Being between 31 years and 40 years of age, having a postgraduate degree or higher, and reporting a monthly expenditure of RMB 5000 or more were found to be significantly associated with knowledge of PrEP and PEP (both P < 0.05). The findings show that both onsite and online health education significantly improved the knowledge of, and increased willingness to use, PrEP and PEP in individuals utilizing PEP services.