WASHINGTON — The Centers for Disease Control and Prevention advised schools on Friday that closings for at least eight weeks might be the most effective way to contain the coronavirus. The Education Department released school districts from a slew of testing and accountability measures required by federal law.

But schools across the country were far ahead of the Trump administration’s advice. A cascade of public school closings gained speed nationwide on Friday, with the largest school district in California, the Los Angeles Unified School District, announcing it was closing, along with the San Diego Unified School District. They joined other large cities like Washington, Miami and Seattle, and more than a dozen states like Virginia, Ohio, Maryland, Pennsylvania, Oregon, New Mexico and Michigan.

At least 21,000 schools have been closed or are scheduled to close, according to Education Week, affecting at least 15 million students. A majority of closings announced by school districts range from two to six weeks, which the C.D.C. considered “short- to medium-term closures” that would “not impact” the huge wave of infections that are expected in the next few weeks.

Danny Carlson, the associate executive director of policy and advocacy for the National Association of Elementary School Principals, called the timing of the C.D.C. guidance “baffling.”