Objective To analyze the epidemiological characteristics and trends of the incidence and mortality of biliary tract cancer in Shanghai from 2002 to 2020. Methods Data on new cases and deaths of malignant tumors of the gallbladder, extrahepatic bile ducts, and other biliary tract organs from 2002 to 2020 were obtained from the Population-based Cancer Registry and Vital Statistics System of Shanghai Municipal Center for Disease Control and Prevention. Cases or deaths, proportion, crude rate, age-specific rate, age-standardized rate (ASR) and others were calculated stratified by year of diagnosis or death, gender and age-group. ASRs were calculated using Segi′s 1960 world standard population. Trends of the annual percent change (APC) of ASRs, age-specific rates and proportions of new cases with selected diagnostic character of biliary tract cancer stratified by different groups were analyzed by Joinpoint analysis software. Results Annual new cases of biliary tract cancer in Shanghai increased from 963 in 2002 to 1 537 in 2020, with ASR of incidence changing from 3.91/10⁵ to 3.59/10⁵. Annual deaths increased from 830 to 1 225, with ASR of mortality decreased from 3.36/10⁵ to 2.69/10⁵. In 2020, the crude rate of incidence of biliary tract cancer was 10.43/10⁵ (9.54/10⁵ in males and 11.30/10⁵ in females) in Shanghai, and the ASR was 3.59/10⁵ (3.54/10⁵ in males and 3.61/10⁵ in females), with no statistically significant gender difference (P=0.731). The crude rate of mortality was 8.31/10⁵ (7.60/10⁵ in males and 9.00/10⁵ in females), and the ASR was 2.69/10⁵ (2.69/10⁵ in males and 2.66/10⁵ in females), also with no significant gender difference (P=0.874). Age-specific nunbers and rates of incidence and mortality generally increased with aging. Stratified by gender, the trend of ASRs of incidence of biliary tract cancer in Shanghai in males showed no significant change (P=0.179) from 2002 to 2020, nor did that of ASRs of mortality (P=0.738). In females, the ASRs of incidence decreased at an average annual rate of 1.58% (P<0.001), while the trend of ASRs of mortality showed no significant change from 2002 to 2011 (P=0.774), but ASRs decreased at an average annual rate of 3.72% from 2011 to 2020 (P<0.001). Among new cases, the proportions of morphological verification increased, while the proportions of imaging verification decreased. The gallbladder was the most common site, but its proportions decreased significantly, whereas the proportions of extrahepatic bile duct increased from 25.75% to 42.88%. Over 60% of cases were unknown stage at diagnosis, while the combined proportions of stages Ⅰ-Ⅲ remained less than that of stage Ⅳ. Conclusions The ASRs for incidence and mortality of biliary tract cancer in Shanghai remain relatively high, with distinct epidemiological characteristics. The improvement in the diagnosis and treatment of biliary diseases maybe have impact on the incidence patterns of biliary tract cancer in Shanghai, but the effect on increasing survival rates and reducing mortality rates is relatively lagging. It needs a big progress to advance the screening, diagnosis, and survival of biliary tract cancer in Shanghai. This study provides a foundation for further research and prevention strategies for biliary tract cancer.