China's western Xinjiang region has written "vocational training centres" for Muslim Uighurs into law amid growing international concern over large-scale disappearances there.
Xinjiang says the centres will tackle extremism through "thought transformation".
Rights groups say detainees are made to swear loyalty to President Xi Jinping and criticise or renounce their faith.
In August, China denied allegations that it had locked up a million people.
But officials attending a UN human rights meeting admitted that Uighurs "deceived by religious extremism" were undergoing re-education and resettlement.
Xinjiang has seen cycles of violence and crackdowns for years. China accuses Islamist militants and separatists of orchestrating the trouble.
What does the Chinese legislation say?
Xinjiang's new legislation is the first detailed indication of what China is doing in the region.
It says examples of behaviour that could lead to detention include expanding the concept of halal - which means permissible in Islam - to areas of life outside diet, refusing to watch state TV and listen to state radio and preventing children from receiving state education.
China says its network of detention centres will also teach Mandarin Chinese, legal concepts and provide vocational training.
Rights groups have criticised the move. Sophie Richardson from Human Rights Watch said the "words on paper outlining grotesque, vast human rights abuses don't deserve the term 'law'".
New law bans promoting of religion
Michael Bristow, BBC News
By giving these camps a legal footing, China appears to have confirmed what many have been saying for months: that it is running a string of re-education camps for Uighur Muslims in Xinjiang in the name of combating extremism.
In newly published regulations detailing the camps, China has given them a vague-sounding name. It calls them "vocational skills and educational training centres".
But it is clear their purpose is not just about giving people the ability to get a better job.
The regulations say they are for people "influenced by extremism". The point is to correct bad behaviour, and ensure those inside them undergo psychological counselling and ideological education.
The camps are part of a broader attack on Islamic extremism in Xinjiang.
The new rules mean it's illegal to spread religious fanaticism by, for example, having "abnormal beards or unusual names".
And extremism is defined so broadly that it even seems to be applicable to parents who complain if their children want to marry someone of a different faith or ethnic group.
Is China cracking down on Islam?
China is also launching a wider campaign against Islamic practices across Xinjiang. It wants to stop the use of halal products that are not food.
One newspaper said the use of the term halal to describe items such as toothpaste blurred the line between religious and secular life and made people prey to religious extremism.
On Monday Communist Party leaders in the regional capital Urumqi led cadres in swearing an oath to fight the "pan-halal trend", AFP reported.
New regulations also make it clear that Muslim women are banned from wearing veils.
Communist party members and bureaucrats have been told to speak Mandarin Chinese in public and not local languages.
What are the camps like?
Former prisoners of the camps have told the BBC of physical as well as psychological torture there. Entire families had disappeared, they said.
In July, a former teacher at one of the camps who fled to Kazakhstan told a court there that "in China they call it a political camp but really it was a prison in the mountains".
The New York Times quoted former detainees as saying that they were forced to sing songs such as "Without the Communist Party, There Would Be No New China" and those who could not remember the words were not given breakfast.
"In the end, all the officials had one key point. The greatness of the Chinese Communist Party, the backwardness of Uighur culture and the advanced nature of Chinese culture," former detainee Abdusalam Muhemet told the newspaper.
The World Uyghur Congress said in a report that detainees were held indefinitely without charge, and forced to shout Communist Party slogans.
It said they were poorly fed, and reports of torture were widespread.
Most inmates have never been charged with a crime, it is claimed, and do not receive legal representation.
However China's state-run English-language Global Times newspaper maintains the tough security measures in the region have prevented it from turning into "China's Syria" or "China's Libya".
Who are the Uighurs?
The Uighurs are ethnically Turkic Muslims mostly based in Xinjiang. They make up about 45% of the population there.
They see themselves as culturally and ethnically close to Central Asian nations, and their language is similar to Turkish.
In recent decades, large numbers of Han Chinese (China's ethnic majority) have migrated to Xinjiang, and the Uighurs feel their culture and livelihoods are under threat.
Xinjiang is officially designated as an autonomous region within China, like Tibet to its south.