Actually most western country citizens planning to visit China's mainland must apply for an entry visa through the Chinese Embassy or Consulate General. ... However, most of citizens do not need a visa to enter Hong Kong, but travelers who plan to visit China's mainland while in the region will need a visa to travel from Hong Kong to China.
However, some cities including Beijing, Shanghai, Guangzhou, Xian, Chengdu, Chongqing etc. that allow 24-hour/72-hour/144-hour direct transit in China, also called the 24-hour/72-hour/144-hour transit without visa, regulates that visa is not required for air, train, and ship passengers transiting in mainland China for a stay of no more than 24 hours/72hours/144 hours before heading for a third country or region for most western country citizens.
Since 2024, more countries are visa free for 15 days to visit Mainland China, please check Chinese Ministry of Foreign Affairs website for the details.