The sheriff of Broward County in Florida has confirmed that 17 people were killed after a gunman opened fire in a high school.

Dozens of police swarmed Marjory Stoneman Douglas High School in Parkland, about 72km north of Miami after the attack and before they took the suspected gunman into custody.

He has been identified as 19-year-old Nikolas Cruz, a former student of the school.

Speaking to media, Sheriff Scott Israel said Cruz was expelled from the school for unspecified disciplinary reasons.

He said that the gunman surrendered to police without a struggle.

Twelve of the dead were killed inside the school building, two others just outside, one more on the street and two other victims died as a result of their injuries at a hospital, Mr Israel said.

He said the victims comprised a mixture of students and adults.

Earlier, Broward County Schools Superintendent Robert Runcie told reporters the school district had no warning of a potential gunman and there was no evidence of more than one gunman.

Students hid in classrooms until they were rescued by police in tactical gear, friends and family members said.

McKenzie Hartley, 19, who identified herself as the sister of a student at the school described the scene in a text message to Reuters: "She heard him shooting through the windows of classrooms and two students were shot."

Panicked parents checked on their children.

"It is just absolutely horrifying. I can't believe this is happening," said one mother of a student.

Her daughter called her to say she was safe but the student also told her mother she heard the cries of a person who was shot.

Live television showed dozens of students, weaving their way between police officers with heavy weapons and helmets, and large numbers of emergency vehicles including police cars, ambulances and fire trucks.

In a post on Twitter, US President Donald Trump said no one "should ever feel unsafe in an American school."

It was the 18th shooting in a US school so far this year, according to gun control group Everytown for Gun Safety.

That tally includes suicides and incidents when no one was injured, as well as an incident in January when a 15-year-old gunman killed two students at a high school in Benton, Kentucky.