Image copyright Facebook Image caption Anderson (R) killed his estranged wife Karen Elaine Smith (L) and an eight-year-old boy

A newlywed who fatally shot his wife and a child before turning the gun on himself at a US school had projected a blissful marriage on social media.

Cedric Anderson entered a primary school on Monday in San Bernardino, California, and gunned down estranged spouse Karen Elaine Smith, 53.

On Facebook, he referred to the special needs teacher as "my wonderful little wife", "sexy" and a "pure spirit".

But some online posts by Anderson, also 53, hinted at a darker side.

Image copyright Facebook Image caption The couple were married in January

The couple, who had reportedly been in a relationship for years, wed in January, but were separated within a few weeks.

Anderson initially seemed to be a smitten husband, rhapsodising about his bride and proclaiming himself "blessed".

"She has no guile or pretense," he wrote in one post of Ms Smith. "She has no ill will toward anyone. (It amazes me!).

"I praise God for such a wonderful Lady!"

Image copyright Twitter Image caption Jonathan Martinez, eight, died in the attack

But in February Anderson exposed a violent streak as he boasted on Facebook of having "almost personally attacked 3 Coaches to get my son Jared a scholarship".

"A father is like a lion. He will kill you for his Blood!" he wrote.

On 12 March, he shared a New York Post video of a man kicking an elderly woman in the face on a bus, entitled: "Can you hear me now?"

Anderson wrote along with the video: "Deranged? Yea!"

Image copyright Facebook Image caption Ms Smith's mother said after the marriage "he showed the other side of him"

Ms Smith's mother, Irma Sykes, told ABC News: "We thought he was a fine person. Until they were married and then he showed the other side of him.

"Which we had never seen before. We were shocked. He began to pick on my daughter and talk down to her.

"And they had dated for four years. And after about three weeks, my husband and I decided, you need to get away from him.

"He is not the kind of person you thought he was."

Media playback is unsupported on your device Media caption Should we stop reporting the name of gunmen in US mass shootings? One expert believes so, and here's why...

In 2013 Anderson was charged with assault and battery, brandishing a weapon and disturbing the peace, but the charges were dismissed a year later.

In 1993, he was charged with two misdemeanour counts of battery in Kern Superior Court, the Los Angeles Times reported.

However, court records show both charges were dismissed six months later.

Somehow, the man who posted a selfie on Facebook a month ago celebrating "date night!!!" with his new wife was able to walk into the classroom on Monday morning where she was teaching and gun her down in cold blood with a Smith and Wesson .357 revolver.

Media playback is unsupported on your device Media caption Students were evacuated from their classrooms

Without saying a word, he discharged 10 shots and stopped to reload, police said.

Two children in the North Park Elementary School special needs class of 15 students were injured in the crossfire, authorities said.

Jonathan Martinez, eight, died and a nine-year-old was in hospital in a stable condition.