US PRESIDENT Barack Obama said he was "deeply humbled" by a visit to the Robben Island prison where Nelson Mandela spent some of his darkest days in jail.

"On behalf of our family we're deeply humbled to stand where men of such courage faced down injustice and refused to yield," Mr Obama wrote in a message in the visitors book co-signed by his wife Michelle.

"The world is grateful for the heroes of Robben Island, who remind us that no shackles or cells can match the strength of the human spirit."

Paying homage to the 94-year-old, who is critically ill in hospital, Mr Obama stared into the stark cell where Mandela spent two thirds of his 27 years in jail, now preserved as a searing tribute to the sacrifice and unbreakable strength of the anti-apartheid leader.

Mr Obama, in a blue wind breaker and slacks and sunglasses, walked with his wife Michelle and two daughters into the bleak lime quarry where 34 anti-apartheid leaders -- including Mandela -- endured hours of backbreaking work.

Guided by former prisoner Ahmed Kathrada, they looked around at its steep walls, overlooked by a cement watchtower with rusting shutters, as Secret Service agents fanned out in front.

Mr Obama was heard telling his daughters how Indian independence hero Mahatma Gandhi started his non-violent political struggle in South Africa.

"One thing you guys might not be aware of is that the idea of political nonviolence first took root here in South Africa because Mahatma Gandhi was a lawyer here in South Africa.

"Here is where he did his first political (activism). When he went back to India the principles ultimately led to Indian independence, and what Gandhi did inspired Martin Luther King," Mr Obama said.

They then made a private visit to the damp cell where Mandela contracted tuberculosis -- the cause of the lung problems that now afflict him in hospital.

Subjected to degrading treatment in "the harshest, most iron-fisted outpost in the South African penal system", Mandela was allowed one visitor for 30 minutes, and one letter, every six months.

He did not so much as touch the hand of his then wife Winnie, having instead to settle for rubbing his nose against a photograph.

"There were many dark moments when my faith in humanity was sorely tested, but I would not and could not give myself up to despair," Mandela wrote in his autobiography Long Walk to Freedom.

The journey to Robben Island, while not Mr Obama's first, carries extra poignancy with Mandela fighting for his life in hospital in Pretoria.

Now a magnet for tourists and a UN World Heritage site, the prison has been starkly preserved as a monument to the hardships endured by those who fought for multi-race democracy.

Mandela went on to two more prisons before walking free, fist clenched, in 1990 and embracing his former enemies in a globally admired lesson of reconciliation.

Originally published as Obama 'humbled' by Mandela prison visit