In most countries, males have ~2–3 times higher incidence of primary liver cancer than females. Sex hormones have been hypothesized to contribute to these differences, but the evidence remains unclear. Using data from the UK Biobank, which included ~200,000 males and ~180,000 postmenopausal females who provided blood samples at recruitment, we estimated hazard ratios (HR2) and 95% confidence intervals (CI) for a doubling in hormone concentration from multivariable adjusted Cox regression for circulating total testosterone, sex‐hormone binding globulin (SHBG), and free testosterone concentrations and risk of primary liver cancer. After a median of 11.8 years of follow‐up, 531 cases of primary liver cancer were observed, of which 366 occurred in males and 165 occurred in females. Total testosterone and SHBG were shown to be positively associated with liver cancer risk in both males and females (Total testosterone HR2: 3.42, 95% CI:2.42–4.84 and 1.29, 0.97–1.72, respectively; SHBG HR2: 5.44, 4.42–6.68 and 1.52, 1.09–2.12, respectively). However, free testosterone was inversely associated with primary liver cancer in males (HR2: 0.42, 0.32–0.55) and no association was observed in females. When analyses compared two main liver cancer subtypes, hepatocellular carcinoma (HCC) and intrahepatic cholangiocarcinoma (ICC), there was evidence of heterogeneity; associations for total testosterone and SHBG concentrations were only positively associated with HCC in both males (HR2: 3.56, 2.65–4.79 and 7.72, 6.12–9.73, respectively) and females (HR2: 1.65, 1.20–2.27 and 6.74, 3.93–11.5, respectively) but not with ICC. Further research understanding the mechanisms of how sex‐steroids may influence liver cancer risk is needed.