Scotland’s next census will include new questions on sexuality and transgender status, after MSPs backed new legislation.

The Scottish Parliament has unanimously approved the Census (Amendment) (Scotland) Bill – which means these issues can be included in the 2021 survey.

However, MSPs stressed the questions were being included on a voluntary basis, with no penalties for those who choose not to answer them.

Equalities campaigners at Stonewall Scotland welcomed the move, with director Colin Macfarlane saying including the questions would “give public bodies vital information to help them meet the needs of Scotland’s lesbian, gay, bi and trans community”.

He added: “Gathering data on LGBT communities in Scotland is an important step towards building a society where LGBT people are truly accepted, everywhere and by everyone.”

Ahead of the debate transgender people and their supporters gathered outside the Scottish Parliament for a demonstration.

There Vic Valentine of the Scottish Trans Alliance said: “For the first time we will be able to get good data on the number and situation of trans and LGB (lesbian, gay and bisexual) people in Scotland via the new voluntary questions”

But the organisation stressed the importance of ensuring that questions are worded in a way that is “sensitive and appropriate”.

Culture, Tourism and External Affairs Secretary Fiona Hyslop, said the census had been used for more than 200 years to gather information needed for government, council and NHS services.

And she added: “This is an important Bill that will enable questions on transgender status and history, and sexual orientation to be asked on a voluntary basis for the very first time, with no penalty for not answering them.”

Ms Hyslop said: “It is widely accepted that there are currently data gaps on sexual orientation and trans status.

“Including questions on these demographics in the census will provide valuable data for public service planning purposes and will help public bodies meet duties under the Equality Act 2010.”

Paul Lowe, registrar general for Scotland, said: “National Records of Scotland are consulting extensively with groups all over Scotland to develop and test proposed questions to ensure they are supported by the public.

“By asking questions which reflect a modern, inclusive Scotland, we will ensure the census will continue to be a vital source of information for decades to come.”