Image copyright AP Image caption President Obama praises his wife in the piece while admitting at times the marriage was unequal

US President Barack Obama has written an essay on why he considers himself a feminist, saying it is "absolutely" men's duty to fight against sexism.

In it he says the most important people in his life have been women, noting the sacrifices made by his wife, Michelle.

He concludes that "21st century feminism" is "the idea that when everybody is equal, we are all more free".

The full article is published in Glamour magazine.

Earlier this year President Obama told a conference on women in Washington "this is what a feminist looks like".

His comments come in the year that Hillary Clinton sealed the Democratic nomination for president, the first time a woman has held the ticket for either major party in the US.

Image copyright White House via Getty Image caption President Obama says he is full of optimism for his daughters Malia (l) and Sasha

Image copyright AFP Image caption He says an unexpected privilege of his presidency has been the opportunity it provides to watch his daughters grow up

In the essay, Mr Obama says that an unexpected gift of his job has been that living in the White House gave him more opportunity to see his daughters grow up.

"One thing that makes me optimistic for them is that this is an extraordinary time to be a woman," he says.

"The progress we've made in the past 100 years, 50 years, and, yes, even the past eight years, has made life significantly better for my daughters than it was for my grandmothers. And I say that not just as president but also as a feminist."

But he adds much more progress needs to be made towards equality, saying "all too often we are still boxed in by stereotypes about how men and women should behave".

And he admits that the burden of childcare fell disproportionately on his wife.

Mr Obama has faced occasional criticism in the past over comments about women, apologising in 2013 after describing California attorney general Kamala Harris as the "best-looking" such official in the country.

His article has delighted some online

Image copyright @JillFilipovic

Image copyright @pamelaribon

Image copyright @RepJudyChu

Mrs Clinton was among those to share the essay

Image copyright @HillaryClinton

But there have been critics

Image copyright @michellemalkin