BEIJING — More than 50 people, almost all of them young children, were hospitalized in southwest China on Tuesday after a man broke into a kindergarten and sprayed them with a corrosive chemical as “revenge on society.”

Fifty-one children and three teachers were injured in the attack in Kaiyuan, in Yunnan province, local authorities said. Two were seriously injured, but their injuries were not life-threatening, according to a report from Xinhua news agency.

A 23-year-old with the family name of Kong was later arrested on suspicion of being the assailant who climbed the wall of the kindergarten and sprayed those inside with sodium hydroxide, also known as caustic soda.

Sodium hydroxide, which is used to make products including soaps and explosives, is very corrosive and can cause irritation to the eyes, skin and mucous membranes, as well as eye and skin burns, according to the Centers for Disease Control and Prevention. The level of harm depends upon the dose and duration of exposure, the agency said.

Kaiyuan police said that Kong, who was found at the back of the kindergarten after the attack, had a troubled family background.

“His parents divorced during his childhood and the lack of family warmth resulted in psychological distortion, plus his work and life was unsatisfactory, which created a pessimistic mentality and thoughts about retaliating against society,” police said in a statement on their WeChat social media account.

There are no school shootings in China because of strict gun-control laws, but there has been a spate of attacks, usually with knives, in recent years.

A man killed eight elementary school students and injured two others on the first day of school in Hubei province in September.

In separate attacks last year, a woman with a knife slashed 14 children at a kindergarten in the western Chinese city of Chongqing in October, and a man stabbed and killed two children outside an elementary school in Shanghai in June. The man arrested in the stabbing said he wanted “to take revenge on society.”

In April last year, nine students were killed as they left their middle school in Shaanxi province for the day when a 28-year-old man, apparently seeking revenge for being bullied when he was a student there, went on a stabbing rampage. Ten others were hurt. The man was convicted and executed.