A new draft law that could make it easier for foreigners to gain permanent residency in China has stirred up a torrent of xenophobia online.

The proposal, released by the justice ministry last week, has been gathering billions of views and a flood of angry posts on social media, targeting Africans in particular.

"China's forty years of family planning policy does not make it a place for foreign trash to soar," wrote one user on the Twitter-like platform Weibo, referring to the one-child birth limit China imposed between 1980 and 2016.

The person went on to use racist language against black people, saying: "Our common Chinese ancestry will not be tainted by Africans."

Some Weibo-users posted videos of black people apparently committing crimes in China, while a campaign to encourage Chinese women to date Chinese men, under the hashtag "China girl", had 240 million views as of Thursday afternoon.

Another widely-shared post on Weibo read: "China is not an immigrant country."

A hashtag related to the law has gained more than 4.8 billion views.

The law -- open to suggestions from the public until March 27 -- proposes allowing foreigners' dependants to apply simultaneously for permanent residency, as well as relaxing education and salary requirements.

State media said less than one percent of foreigners in China have permanent residency.

Migration from Africa has risen in recent years as China has stepped up its diplomatic links and investments with the continent
Migration from Africa has risen in recent years as China has stepped up its diplomatic links and investments with the continent AFP / FRED DUFOUR

The draft bill comes at a time when China is seeking to expand its global influence and attract foreign exchange and investment.

Its massive Belt and Road infrastructure investment project has funded thousands of lucrative scholarships for students from developing countries.

But there have been points of tension, including a crackdown on illegal immigrants in commercial hub Guangzhou's "Little Africa" which left many complaining of hard treatment from authorities.

There are also long-standing anxieties about perceived preferential treatment for foreigners in China, especially international students.

"For a long time, some foreigners in China have secretly received 'superior treatment' as citizens," wrote Hu Xijin, editor of the nationalistic Global Times.

Last July, Shandong University apologised after a backlash over a policy that introduced foreign students to local students of the opposite sex.

Heather Li, a China-Africa business consultant, said she was "really shocked" by the extent of the online racism.

She used to tell her African friends that many Chinese people were friendly and curious about their culture, despite their occasional encounters with prejudice.

"But after seeing it on Weibo, I realised there was so much more to it, because people were using very strong language and really disrespecting people from other races," she said.