BEIJING/HONG KONG (Reuters) - Anyone who mocks China's national anthem faces up to 15 days in police detention after parliament criminalised such acts in a new law on Friday (Sept 1) that covers Hong Kong and Macau.

Since taking over as president, Chinese leader Xi Jinping has ushered in new legislation aimed at securing the country from threats both within and outside its borders, besides presiding over a sweeping crackdown on dissent and free speech.

Protecting "the dignity of the national anthem" will help"promote patriotism and nurture socialist core values", says the new law passed by the National People's Congress (NPC).

It governs when, where and how the anthem, the "March of the Volunteers", can be played.

The law bans its use as background music and in advertisements, rules out playing it at funerals and on other"inappropriate occasions" and prescribes administrative detention for any "distorted" or "mocking" renditions.

Those attending public events must stand to attention and sing in a solemn manner when the anthem is played.

The new law brings treatment of the anthem into line with desecration of China's national flag, or its emblem, which has been a criminal offence punishable by up to 15 days' detention since the 1990s. Those laws also apply in Hong Kong and Macau.

Wu Zeng, the office head of the NPC's national laws panel, confirmed that lawmakers had agreed the law should also apply to Hong Kong and Macau by being written into their constitutional provisions, the Basic Laws.

The law has fuelled concern in Hong Kong, whose residents have grown nervous over China's perceived encroachment of the city's autonomy following such events as the disappearance of booksellers who later emerged in mainland Chinese custody.

Hong Kong lawyer and pro-democracy lawmaker Tanya Chan said she expected "a series of obstacles" when the former British colony, which returned to Chinese rule in 1997, adopts the law.

"The rights and freedoms protected under Hong Kong laws have come under challenge in recent years," she said. "So it is right for people to be concerned."

The city's Justice Secretary, Rimsky Yuen, said he hoped "the intention of the national law would be upheld without affecting Hong Kong people's basic rights and freedoms".

In 2015, Hong Kong football fans booed the Chinese anthem during a World Cup qualifier, prompting a fine for the territory's football association from world body FIFA.

Last month, Shanghai police detained three men for having "hurt patriotic feelings" by dressing up as Japanese soldiers and posing for photographs outside a memorial to China's war with Japan, state media said.