Barack Obama is slamming hip-hop and rap music for perpetuating stereotypes rooted in toxic masculinity.

The former president took the stage with Steph Curry at the My Brother's Keeper Alliance summit on Tuesday, celebrating the fifth anniversary of the youth support and violence prevention group he created during his time in office.

He spoke about what it means to 'be a man' and how to fight stereotypes of masculinity that 'trap' young men of color and often emerge in hip-hop and rap music.

'If you were very confident about your sexuality, you don't have to have eight women around you twerking,' he joked as the crowd erupted with laughter.

Barack Obama blasted hip-hop and rap music for promoting toxic masculinity during the My Brother's Keeper Alliance event on Tuesday in Oakland, California

'Let’s face it a lot of hip hop and rap music is built around me showing how... I can disrespect you and you can’t do nothing about it,' he said to the crowd as he shared the stage with Golden State Warriors star Steph Curry

At the conference he spoke about what it means to 'be a man' and how to fight stereotypes of masculinity that 'trap' young men of color and often emerge in hip-hop and rap music

Obama created the initiative My Brothers Keeper in 2014 to 'break down barriers that too often leave boys and young men of color at a disadvantage'

'Let’s face it, a lot of hip hop and rap music is built around me showing how I got more money than you, I can disrespect you and you can’t do nothing about it, I’m going to talk about you and punk you,' Obama said.

'Ironically, that actually shows the vulnerability that you feel,' he added.

'Let me say this, if you were really confident about your financial situation you probably aren’t going to be wearing an eight pound chain around your neck,' he said.

Obama then touched on hip-hop's portrayal of male sexuality and brought up the twerking joke adding, 'I've got one woman who I'm very happy with. And she's a strong woman.'

Obama hilariously opened his speech introducing himself as 'Michelle's husband' and Curry followed suit introducing himself as 'Ayesha's husband'.

Obama shared his sharp critic on rap stars like Tyga who surround themselves with twerking video vixens. Tyga's music video for Kream pictured above

The former president smiled as he took questions at the My Brother's Keeper Alliance Summit in Oakland, California on Tuesday evening

Steph Curry also shared his own two cents talking about the importance of men sharing their feelings, revealing that the locker room is a sacred place for him and his teammates

Singer John Legend performed at the My Brother's Keeper Alliance Summit on Tuesday as well

'Racism historically in this society sends a message that you are "less than". We feel we have to compensate by exaggerating stereotypical ways are supposed to act. And that’s a trap,' Obama said at the two-day conference in Oakland, California.

Curry, who is a mentor with the program, pushed the conversation further saying men have to be 'open about their feelings'. He revealed the Golden State Warriors locker room is a place where he and his teammates do so.

My Brothers Keeper conference will last for two days. On Tuesday Obama invited two dozen young men of color to the stage where they talked about music, confidence, sexuality, and toxic masculinity.

Boys and men of color flocked from across the nation to attend the conference, hailing from Los Angeles, New York and Nashville.

When he created the initiative in 2014, Obama described the group's mission as 'working to break down barriers that too often leave boys and young men of color at a disadvantage'.

He left the group on Tuesday with an encouraging message to be compassionate and rethink what masculinity means.

Barack Obama had dinner on Monday night at International Smoke in San Francisco. Chef Michael Mina shared a photo of him posing with Obama and Steph and Ayesha Curry

'All of us have to recognize that being a man is first and foremost being a good human. that means being responsible, working hard, being kind, respectful, compassionate,' Obama said.

'The notion that somehow defining yourself as a man is dependent on, are you able to put somebody else down...able to dominate...that is an old view,' he added.

He then spoke on the importance of creating spaces 'where young men of color, and young men generally, don’t feel as if to be respected they have to act a certain way.'

'If you’re confident about your strength, you don’t need to show me by putting somebody else down. Show me by lifting somebody else up,' Obama said.

Impressed Curry replied: 'I've just been mentored right there.'

John Legend later came out to perform for the audience with a moving performance.

One day earlier Obama spent quality time with Curry and his wife Ayesha as well as Hollywood A-listers Chrissy Teigen and John Legend in San Francisco.

The group dined at International Smoke - a high-end barbecue restaurant run by actress Ayesha and celebrity chef Michael Mina

Chef Mina later shared a photo on Instagram of him posing with Obama and the Currys.