“X” marks the spot — for gender identity.

Mayor de Blasio signed a bill into law Tuesday allowing New York City residents to select a third gender category on their birth certificates without having to get approval from a medical professional.

“New Yorkers should be free to tell their government who they are — not the other way around,” de Blasio said at the Edie Windsor SAGE Center in Manhattan.

Beginning Jan. 1, a “nonbinary” identity category known as “X” will be available on birth certificates and other official government documents for city residents who don’t consider themselves male or female.

Specifically, transgender New Yorkers will no longer need a letter from a physician or an affidavit from a licensed health- care provider to change their gender.

They’ll be able to submit their own affidavit requesting a gender-identity change.

With the change, New York joins California, Washington, New Jersey and Oregon in providing a third gender category on birth certificates.

Washington, DC, allows it on driver’s licenses.

De Blasio was joined at the event by First Lady Chirlane McCray, a longtime gay-rights activist, and City Council Speaker Corey Johnson, who sponsored the bill approved on a 41-to-6 vote by the council last month.

Johnson said he has never been more proud of any legislation he’s sponsored.

He also said he was pleasantly surprised no one testified against his bill — considering that opposition helped shoot down a similar measure more than a decade ago during the administration of Mike Bloomberg.

Tanya Asapansa-Johnson Walker, co-founder of the New York Transgender Advocacy Group, spoke at the bill-signing about her college days on Staten Island, when she had to slip professors pieces of paper to be identified correctly.

She said she also often sat in the back of the room over concern about her gender identity.