Education secretary John Swinney announced the move and said it was “in light of updated scientific and health advice”.
The new rules mean pupils in S4 to S6 and their teachers must wear face coverings at all times including while in classrooms and while moving around the school or in communal areas.
This applies to areas in Level Three and Four and will come into force from Monday, affecting much of the country, including Edinburgh and the Lothians.
The Scottish government added that face coverings should be worn by adults “at all times” when two metre social distancing is not possible, with parents and other visitors expected to do the same across all restriction levels.
Edinburgh school holidays: full list of term dates and breaks - including October half term and Christmas
Edinburgh nursery were 'not respectful of children's personal space', care report finds
These are the 10 best Edinburgh schools in 2020 as ranked by Highers results
Edinburgh's Trinity Academy gets £10m sport and outdoor centre as first phase of new school
Edinburgh and Lothian School holidays 2022: School summer holiday dates 2022, when will schools start back?
There is also updated advice to children and teachers considered at high risk to Covid-19.
Deputy first minister John Swinney said: “Keeping schools open remains our priority but that can only be the case if schools are safe. There have been tremendous efforts applied by staff and pupils to ensure this is the case and I thank them all for their efforts.
"We constantly review the guidance on school opening along with our local authority partners, trades unions, parental representatives and other stakeholders to ensure we are taking all the necessary measures to ensure our schools are safe.
"This strengthened guidance, produced in light of updated scientific and health advice, adds to the health mitigations that have been in place since schools opened in August.
“It is vital that all the measures are followed rigorously in schools. Doing that – together with the collective efforts of all of us across wider society – will help to ensure that schools can safely remain open.
“None of the levels in the framework require any automatic move to school closures or blended learning. However, no one can predict what the coming weeks and months will bring.
"Remote learning remains an important contingency for schools at all levels of the strategic framework and there has been considerable progress made in the provision of remote learning, should that be required.”