Viruses are the major drivers shaping microorganismal communities, and impact marine biogeochemical cycling. They are affected by various environmental parameters, such as salinity. Although the spatiotemporal distribution and dynamics of virioplankton have been extensively studied in saline environments, few detailed studies of community structure and function of viruses along salinity gradients have been conducted. Here, we used the 16S and 18S rRNA gene amplicon and metagenomic sequencing from a subtropical estuary (Pearl River Estuary, PRE; located in Shenzhen, Guangdong Province, China) to explore how viral community composition and function vary along a salinity gradient. Results showed that the detected viruses were mainly bacteriophages. The double-stranded DNA viruses were the most abundant (especially Siphoviridae, Myoviridae, Mimiviridae, Phycodnaviridae, and Podoviridae), followed by a small number of single-stranded DNA (Circoviridae) and RNA (Retroviridae) viruses. Viral biodiversity significantly declined and community structure varied greatly along the salinity gradient. The salinity, ammonium and dissolved oxygen were dominated factors influencing the community composition of viruses. Association network analysis showed that viruses had a negative effect on multiple host taxa (prokaryotic and eukaryotic species). Metagenomic data revealed that the main viral functional potential was involved in organic matter metabolism by carbohydrate-active enzymes (CAZymes). Deeper comparative functional analyses showed that viruses in the low-salinity environment had more carbohydrate-binding module and glycosidase hydrolases activities than those under high-salinity conditions. However, an opposite pattern was observed for carbohydrate esterases. These results suggest that virus-encoded CAZyme genes may alter the bacterial metabolism in estuaries. Overall, our results demonstrate that there is a spatial heterogeneity in the composition and function of virioplankton along a salinity gradient. This study enhances our understanding of viral distribution and their contribution to regulating carbon degradation throughout environments with varying salinities in subtropical estuaries.