Hepatocellular carcinoma (HCC) affects males in a significantly higher proportion than females and is one of the human cancers etiologically related to viral factors. Many studies provide strong evidence of the direct role that hepatitis B virus (HBV) plays in hepatic carcinogenesis, but the functions of HBV surface antigen (HBsAg) and X protein (HBx) in hepatocarcinogenesis through direct or indirect mechanisms are still being debated. We generated two HBV gene knock-in transgenic mouse lines by homologous recombination. HBsAg and HBx genes were integrated into the mouse p21 locus. Both male and female p21-HBx transgenic mice developed HCC after the age of 18 months; however, male p21-HBsAg transgenic mice began to develop HCC 3 months earlier. The expression of a number of genes related to metabolism and genomic instability largely resembled the molecular changes during the development of HCC in humans. ER-beta (estrogen receptor-beta) was extremely up-regulated only in tumor tissues of male p21-HBsAg mice, providing genetic evidence that HBsAg might be the major risk factor affecting the gender difference in the causes of HCC. In conclusion, these mice might serve as good models for studying the different roles of HBsAg and HBx in early events of HBV-related hepatocarcinogenesis.