At least three pupils are dead and 23 injured after a walkway collapsed at a school outside Johannesburg, South African officials have said.

Panyaza Lesufi, head of education for Gauteng province, posted the toll on Twitter shortly after the collapse at Hoerskool Driehoek high school in Vanderbijlpark. Two boys and a girl were killed, he said.

“It is painful to see those tiny bodies in that state,” Mr Lesufi said. He reported “scores” trapped but an Associated Press witness later said no one remained in the rubble.

“When we arrived we found that there are still children underneath,” said Kay Makhubela, spokesman for Gauteng police. He said about nine people were seriously injured.

The students at the school are aged 13 to 18, local broadcaster eNCA reported.

It was not immediately clear what caused the collapse. Police said engineering reports would form part of the investigation.

Local media posted photos of a large slab and scattered bricks with the scene blocked off by emergency tape.

The national Department of Education extended condolences to the families of the students killed. Young boys from a neighbouring school came by to lay flowers.

A pastor leads prayers at the school
A pastor leads prayers at the school (AP)

“My heart goes out for the school because a lot of my friends were (there),” said one of the boys, Herco Lintvelt.

“I hope they can build the school up again. And I hope everyone who is here must be fine.”

A statement by AfriForum, a civil society group that represents the rights of Afrikaners, sent out a notice urging people to avoid the area so as not to interfere with the work of emergency responders.