Slightly more middle-school students took health classes last year, which are required by city rules to include sex education, according to data released Friday by the New York City education department. Still, about 40 percent of eighth graders went without the state-mandated classes.

Meanwhile, less than 11 percent of health instructors received sex-ed training within the past two years, according to the data, which the department must release under a 2016 law passed by local lawmakers concerned that too many students were not taking health classes.

State law requires that students receive at least one semester of health education in both middle and high school, and the New York City education department calls for sex ed to be included in grades 6-12 health classes. But the data show the city is falling short of those mandates.

About 77 percent of middle schools provided health instruction in 2016-2017 — up three percentage points from the previous year, according to the data. The share of eighth-grade students who were signed up for at least one semester of health was 60 percent, also up three percentage points.

In a September report, city Comptroller Scott Stringer said he was “alarmed” by the number of eighth-graders missing out on health education. He pointed to data showing that teen pregnancy rates in parts of the city far exceed state averages, and that sexually transmitted infections have ticked up among New York City teens in recent years.

On Friday, Stringer welcomed the small increase in health education offered at middle schools last year, but said the department of education needs to do better.

“The DOE should not be patting itself on the back,” he said in an emailed statement. “Instead, the city should be doubling down on efforts to provide the comprehensive, medically accurate information that all students need to lead healthy lifestyles.”

Youth groups working with the New York Civil Liberties Union recently surveyed high school students and found that only a quarter said they had been taught sex ed in school. Those courses rarely touched on issues affecting lesbian, gay, bisexual, and transgender youth, according to the survey results.

Meanwhile, the Trump administration is cutting short federal grants for teen-pregnancy reduction programs. Some groups receiving that money work in New York City schools — making access to sex education in class even more important, advocates and elected officials say.

The city recently created a sex-ed task force, as required by a new City Council law. The roughly 30-member advisory group — which includes students, parents, educators, and education department representatives — was required to submit its recommendations by Friday but missed the deadline. Education department spokesman Doug Cohen said the “full” recommendations are not expected until next year.

The department has also highlighted health education in the “compliance checklists” it sends schools, and is piloting a new health curriculum in some elementary schools, officials said.

“We have more work to do to,” Deputy Chancellor Elizabeth Rose said in an emailed statement. “We are committed to working closely with schools to ensure that all students receive the high-quality health instruction they need.”