The use of police stop-and-search powers must be necessary, proportionate and lawful, according to a new code of practice laid before the Scottish Parliament.

The code, drawn up by an advisory group led by John Scott QC, will come into force in May if it is approved by MSPs.

It is being introduced following concerns over the number of people being searched without a legal basis.

The number of stop-and-searches has fallen dramatically since 2013/14 when the scale of their use was first exposed.

Statistics show 888 consensual searches and 20,665 statutory searches were conducted between April 1 and September 30 2016.

This compares with 450,173 consensual searches and 192,470 statutory searches in 2013/14.

Once the code comes into force, non-statutory or ''consensual'' stop-and-searches will be banned entirely.

The legal basis for statutory searches is "reasonable grounds" for suspicion that the person has committed, is committing or is about to commit a crime, or is in possession of a prohibited item.

The code makes clear the person's physical appearance, clothing, "generalisations or stereotypical images" or record of previous convictions cannot be used alone as a reason for a search.

It states the search must be required to "locate a harmful item or confirm the possession of an illegal item", and in every case a police officer must "balance the rights of the individual against the perceived benefit of the search".

It contains specific guidance on stop-and-search of children, including the presumption a search will not take place if it appears the child lacks the capacity to understand what it may involve or why it is necessary.

The code also sets out the recording requirements for searches.

Justice Secretary Michael Matheson said: "This new code is about finding that balance and maintaining the trust between the police and the public.

"People's views about when and how stop-and-search should be used have been integral to the shaping of the new code.

"With this new code we will ensure stop-and-search is carried out with the fairness, integrity, respect and accountability that we expect from our police officers in all of their duties."

Mr Scott QC said: "This code will complete the process of change from non-statutory searches to statutory searches.

"The code has been substantially revised thanks to responses in the formal consultation process and the contribution of others in the last few months - leading academics; relevant organisations dealing with children, young people and those with specific vulnerabilities; several government departments; and officers of the national stop and search unit."

Assistant chief constable Mark Williams said the force welcomed the code, adding officers are being trained in advance of its introduction.

The Liberal Democrats had campaigned against the use of non-statutory searches and called for the introduction of the code.

MSP Liam McArthur said: "MSPs will now look at the fine detail of the code to ensure the right protections are in place, the right information will be recorded and no more abuses can occur.

"This is welcome news for the officers who were under pressure to conduct searches they didn't believe in and for everyone who agrees with Liberal Democrats that any police search must be justified and proportionate."