Now, it is extending its efforts into another corner: the outside lawyers who represent the company in legal matters.

Facebook is requiring that women and ethnic minorities account for at least 33 percent of law firm teams working on its matters.

Numbers alone, however, are not enough, under a policy that went in effect on Saturday. Law firms must also show that they “actively identify and create clear and measurable leadership opportunities for women and minorities” when they represent the company in litigation and other legal matters.

Those opportunities “include serving as relationship managers and representing Facebook in the courtroom,” Facebook’s general counsel, Colin Stretch, said in an interview. The legal department, he said, has for the last few years been working on increasing diversity at all levels.

“Firms typically do what their clients want,” he said. “And we want to see them win our cases and create opportunities for women and people of color. We think the firms are ready — our articulation gives not just permission but a mandate.”

For Facebook, the move on outside lawyers is happening even as the company’s efforts at improving diversity in its own work force have so far shown little progress.

According to statistics released last year, blacks and Hispanics last July accounted for only 3 percent each of senior leadership, and women made up an additional 27 percent. Hiring for the 12 months beginning with July 2015 showed something of an improvement: Of those newly recruited to senior leadership posts, 9 percent were black, 5 percent were Hispanic and 29 percent were women.

To improve those numbers, Facebook announced last year that it would focus on recruiting and retention. The company is also establishing programs to help underrepresented college students, as well as younger students in public schools nationwide, develop interests in coding and engineering. In addition, Facebook is reaching out to families who want to learn more about programming.

And when it comes to improving diversity among its outside lawyers, Facebook is part of a growing trend.

A number of general counsels across corporate America are pressing their outside firms to make their teams more diverse — in terms of ethnicity, gender, sexual orientation and even disability — at all levels of seniority, not just among junior associates.

MetLife says it is announcing a new policy this month; HP in February adopted a more stringent program. The moves are an acknowledgment that the numbers of women and minorities at law firms have barely budged over the past 20 years.

“Law is the least diverse white-collar profession,” said Jean Lee, the chief executive of the Minority Corporate Counsel Association, an organization that focuses on the hiring, retention and promotion of diverse lawyers. “A lot of companies made a concerted effort to increase diversity internally, and now they are demanding diversity at the firms they use.”

“One of the challenges in the legal profession is that, despite all of the focus, the lack of diversity is a stubborn and persistent problem,” said Kim Rivera, HP’s general counsel. “We think we can help if we can be clear and unambiguous and hold firms financially accountable.”

HP now requires its outside law firms to have at least one diverse so-called relationship partner or at least one “woman and one racially/ethnically diverse attorney each performing at least 10 percent of the billable hours worked on HP matters.” (A woman who is also a minority will cover the requirements as long as she bills the requisite 10 percent.)

Failure to comply, under the policy, would result in a 10 percent “diversity holdback” of fees, but with a one-year grace period.

Ms. Rivera said the reaction to the new policy had been positive. “I’ve gotten dozens of calls and meeting requests largely asking how to partner with us to have the program succeed,” she said.

Zakiyyah Salim-Williams, the chief diversity officer for Gibson, Dunn & Crutcher, which counts both HP and Facebook among its clients, said she was not fazed by the new requirements.

“We have a large number of diverse lawyers and we always try to staff our teams to reflect that,” she said.

Mr. Stretch of Facebook says its legal department will work with outside law firms in their efforts, tracking results, not surprisingly, through a variety of metrics.

It’s not just tech companies that are pushing their outside counsel. MetLife’s general counsel, Ricardo Anzaldua, will meet this month with representatives of some of the 50 firms the company retains to review an initiative to spur retention and sponsorship of women and diverse lawyers.

Under the program, the firms “must make sure that the junior diverse talent has sponsorship among the senior lawyers and that they get the best coaching and nurturing they can provide.” MetLife will evaluate the results in 2018; underperforming firms will have six months to improve or be dropped.

Mr. Anzaldua’s mandate echoes his own in-house initiatives. “A few years ago we began to identify and coach those with high potential to become the future leadership pipeline,” he said. “While the initiative doesn’t exclude white men, the proportion of women and people of color in that pipeline is more than 60 percent, reflecting the fact that we have an influx of talented women and people of color in the lower ranks.”

Some companies take a more fluid approach. While Verizon Communications has no numerical target, its general counsel, Craig Silliman, said, “diversity of the team is one of the specific criteria we use when we bid out a matter,” in addition to strategic approach, cost and other factors.

Morgan Stanley’s chief legal officer, Eric Grossman, in addition to encouraging diverse teams, also annually names one of its outside law firms as the recipient of a leadership award in diversity and inclusion. Firms vie for the award, which depend on a variety of factors.

“We put a lot of weight not just on the diverse and female attorneys who work on Morgan Stanley matters, but also on how many diverse lawyers they have in the firm and the depth of their sponsorship programs they have to promote overall diversity. We recognize that it just doesn’t happen on its own,” he said.

The possibility of a fee reduction or being dropped from the roster of approved firms could be an effective tool to make it happen.

“Companies are now using a carrot and stick approach because the carrot approach alone didn’t work,” said Ms. Lee of the Minority Corporate Counsel Association.