We assessed prevalence and factors associated with hepatitis B in a cross section of HIV-infected primary care and antinatal clinic patients in South Africa and evaluated a rapid hepatitis B surface antigen (HBsAg) assay. We enrolled 998 patients; 88% were women, median age was 29 years and median CD4 count was 354 cells/mm(3). HBsAg enzyme-linked immunosorbent assay (ELISA), anti-hepatitis B core (HBc) antibodies and hepatitis C virus antibody were positive among 4.2%, 37% and 0.1% of subjects, respectively. Univariate and multivariate associations were assessed using logistic regression. Anti-HBc antibodies were associated with alcohol use, traditional medicines and higher CD4 counts; HBsAg positivity was associated with lower CD4. Compared with the HBsAg ELISA, a rapid HBsAg test had a sensitivity of 75.0% and specificity of 99.6%. In conclusion, we identified a moderate prevalence of both HBsAg and anti-HBc. Importantly, we found that subjects with HBsAg positivity had lower CD4 counts.