Introduction: Hepatitis B virus (HBV) infection has been associated with chronic hepatitis and cirrhosis. Patients with inflammatory bowel disease (IBD) may be at a higher risk of HBV infection reactivation, especially those on biologic therapies. This study intends to compare the effectiveness of the HBV vaccine in patients with ulcerative colitis (UC) on infliximab (IFX) compared to those on 5-aminosalicylic acid (5-ASA). Methods: Patients with UC aged >18 years old were prospectively enrolled in the study. The patients were divided into two groups: patients treated with 5-ASA (control group) and patients treated with IFX (study group). HBV vaccination was administered (20 mcg) following the standard regimen, and Hepatitis B serum antibody (HbsAb) titers were assessed three months after the final dose. The response to HBV vaccines was categorized as an ‘adequate’ immune response (≥10 IU/L) and ‘effective’ immune response (≥100 IU/L). Results: In our final analysis of 118 patients with UC, 54.2% were male and 52.5% had extensive colitis. HBsAb titer levels were significantly higher in the 5-ASA group (126.7 ± 37.5) compared to the IFX group (55.5 ± 29.4). Stratifying HBsAb levels into two categories (≥10–99 IU/L and ≥100 IU/L) revealed a significantly greater proportion of subjects in the 5-ASA group with levels ≥100 IU/L compared to the IFX group (76.7% vs. 12.1%, p < 0.001). Logistic regression analysis demonstrated that patients with UC receiving 5-ASA were 23.94 times more likely to exhibit HBsAb levels ≥ 100 compared to those treated with IFX (OR = 23.94, 95% CI 8.89–64.49). Conclusion: The immune response to hepatitis B vaccination in patients with ulcerative colitis treated with IFX is attenuated compared to those treated with 5-ASA. Therefore, emphasizing the importance of HBV vaccination for patients with IBD before starting anti-TNF therapy, especially IFX, and advocating for screening is imperative in high-risk countries. Determining what levels of HBsAb provide protection and what happens to the levels over time after a booster dose are important clinical questions to be answered by follow-up studies.