Five hundred new health visitors will be recruited over the next four years as a result of a £40 million investment from the Scottish Government.

Health Secretary Alex Neil said the additional staff would play a key role in tackling health inequalities.

He announced the new positions are being created during a visit to the Goodtrees Neighbourhood Centre in Edinburgh with Children's Minister Aileen Campbell.

It comes after Holyrood passed legislation earlier this year which will result in a "named person" being appointed for every child in Scotland.

Health visitors will play a crucial part in this, often taking on the role for young children.

The Scottish Government is to invest £1.5 million this year in health visitor education, with a further £2 million towards creating 50 new health visitor posts.

Funding for the new posts will then rise to £6.8 million next year, £12.8 million in 2016-17 and £20 million in 2017-18.

Mr Neil said: "Health visitors play a vital role in our communities and they are at the core of delivering universal services. We want to invest in health visitors as the first part of the work to fulfil our vision to revolutionise children's services and make Scotland the best place to grow up, which is why we will be delivering 500 more health visitors over the next four years.

"As front-line NHS workers working with people to reduce health problems from an early age, these new health visitors will play a key role in the Scottish Government's efforts to reduce health inequalities."

Ms Campbell said: "Health visitors who support infants and their parents and carers in the earliest years of life play a key role in delivering a universal service to children and families and the Scottish Government is committed to supporting them.

"I'm delighted that we can announce this extra investment in the workforce to build on the excellent work they are already doing and to ensure our children get the best start in life."

The investment was welcomed by Theresa Fyffe, director of the Royal College of Nursing Scotland, who said: "Health visitors make a critical difference to the health and wellbeing of the future lives of children and families. That's why we've been campaigning for the past year for the Scottish Government to invest in having the right number of fully resourced health visitors in place.

"We're pleased the Scottish Government has been listening and today's announcement is a significant step in the right direction - we will continue to engage with the Scottish Government to make sure Scotland's families do have ready access to and support from health visitors."

Conservative health spokesman Jackson Carlaw said: "We agree with the RCN that it is just a beginning. More health visitors are just part of the urgent need to invest in Scotland's NHS.

"The Scottish Conservatives have been arguing for a national, universal, GP-attached health visiting service throughout the last two parliaments. We welcome today's major announcement from the Scottish Government, which is an important first step in giving families across Scotland equal access to such an important service for children in the early years.

"These 500 new health visitors should be targeted at areas with high health inequality as part of a successful preventative health agenda."

Tam Baillie, Scotland's Commissioner for Children and Young People, said health visitors are "absolutely central to delivering the ambitions of the Children and Young People (Scotland) Act".

He added: "I have previously said that for us to be confident that health visitors could properly fulfil their responsibilities under the 'named person' proposals in that Act, more health visitors were urgently needed and this action will make a big difference."

But he said: "While Scottish Government deserves credit for taking action on the issue through the additional investment, challenges remain. We need to ensure we robustly monitor the numbers of properly trained health visitors to fulfil the commitment and we need them as soon as possible to ensure that children born today get the services they have a right to expect and that we have a responsibility to deliver."

The No To Named Person campaign group has been set up to challenge the plans, and a spokesman said: "The creation of jobs is usually to be welcomed but this is nothing more than a needless investment in state-sponsored social engineering."