Mandatory sex-education classes are returning to New York City public schools for the first time in nearly two decades, officials said on Wednesday.

Public schools will be required to teach a semester of sex education to sixth or seventh grade classes and again to ninth and tenth graders, Chancellor Dennis Walcott said in a letter announcing the plans.

The New York Times reports that middle and high school students will be required to take sex-education classes beginning this year.

The curriculum includes lessons on how to use a condom and the appropriate age for sexual activity, where classes can be incorporated into existing health education courses.

The new mandate calls for students to take one semester of sex education in 6th or 7th grade, and again in 9th or 10th grade. Children as young as 11 will participate in discussions on topics like pregnancy and the risks of unprotected sex.

Opposition from conservative groups and some school board members defeated a city mandate approved in the 1980s for a sex-education curriculum.

Parents will be able to have their children opt out of the lessons on birth-control methods.

Separately, in 1987, New York state mandated an HIV/AIDS curriculum in every school from kindergarten through 12th grade which is still in effect.

New York state also requires middle and high school students take one semester of health education classes, but some schools do not include sex education in health classes.

"While many of our schools have already voluntarily taken steps to include sex education in their curriculum, some have not, leaving us with an uneven system that I believe does not serve our students well," Walcott said.

Walcott said parents can choose to take their children out of classes on birth-control methods if they want.

The New York Civil Liberties Union praised the plans, saying in a statement: "There is a consensus among public health experts and the public that age-appropriate, medically accurate comprehensive sex education is essential for providing teens with the tools to become healthy adults."