Supreme Court Justice William H. Rehnquist, speaking out on a subject that has become an important issue in the presidential campaign, said yesterday that nothing is wrong with presidents trying to name to the court jurists who share their political and social views.

But he added that past efforts to do this have been at best only partly successful.

Rehnquist, a conservative nominated in 1971 by President Richard M. Nixon, mentioned neither President Reagan nor Democratic presidential nominee Walter F. Mondale during a speech analyzing court appointments from presidents James Madison to Franklin D. Roosevelt.

But his analysis undercuts a campaign theme frequently raised by Mondale, who has argued that Reagan, if reelected, would pack the court with conservatives who would dominate it for years to come.

Rehnquist is the fourth justice in recent months to break the court's traditional silence on political issues to talk about the court in a way that could be perceived as an attempt to influence public opinion.

The speech was delivered at the University of Minnesota Law School, Mondale's alma mater. Rehnquist's office said Rehnquist prepared the speech last March.

Justices Thurgood Marshall, John Paul Stevens and Harry A. Blackmun, recently have criticized decisions made by an increasingly cohesive conservative majority.

"It seems fitting," Rehnquist said yesterday, "particularly in the year of a presidential election, to inquire into what history shows as to the propensity for presidents to pack the court, and the extent to which they have succeeded . . . . "

Rehnquist rejected the idea that a president should strive to "balance" the court. "There is no reason in the world why a president should not . . . appoint people . . . who are sympathetic to his political or philosophical principles," Rehnquist said.

The president is the "one official who is elected by the entire nation," he said, and his election is the only way the public has "something to say about the membership of the court."

Blackmun said last month that, with five of the court's nine justices over 75 years old, there are "bound to be vacancies" over the next four years and that the replacements will have a "real bearing" on the court, "characterizing it to the end of the century."

But Rehnquist said that nominees often act unpredictably and that "a number of factors militate against a president having anything more than partial success," especially in the long run, in trying to structure a court to his liking.

Those factors, Rehnquist said, include the extent of the president's power to appoint whoever he wants.

"Presidents who wish to pack the Supreme Court, like murder suspects in a detective novel, must have both motive and opportunity," Rehnquist said.

He cited President Madison's desire for a "nominee who had the right philosophical credentials." But Madison decided not to risk a battle with the Senate and settled for someone who could be easily confirmed, he said.

Another factor limiting presidential influence over the court, Rehnquist said, is that a nominee may "change his way of looking at things when he 'puts on the robe.' "

Presidents such as Abraham Lincoln, who had five appointees, and Franklin D. Roosevelt, who had eight, had short-term successes with their nominees, Rehnquist said. But issues changed, and the nominees who were united on Civil War or New Deal issues soon parted company as new issues came before the court, he said.

The court, "as much as anything," tends to foster individualism, rather than bloc voting, Rehnquist argued, noting that lifetime tenure makes justices independent of public opinion, of the president and "of one's eight colleagues as well."

"When one puts on the robe," Rehnquist said, "one enters a world of public scrutiny . . . which sets great store by individual performance, and much less store upon the virtue of being a 'team player.' "