Lawyers cannot be forced to pay state bar dues that are used for political or ideological activities with which they disagree, the Supreme Court ruled unanimously yesterday.

The court said in a challenge brought by 21 members of the California bar that the use of mandatory dues for such activities violated the lawyers' constitutional rights of free speech if the expenditures are not needed to regulate the legal profession or improve legal services in the state.

The lawyers challenged the use of the dues for such activities as lobbying on state legislation, endorsing a gun control initiative and a nuclear weapons freeze, and opposing federal legislation that would limit court jurisdiction over abortion, school prayer and busing. In California, as in 31 other states and the District, lawyers must belong to the state bar in order to practice there.

Chief Justice William H. Rehnquist, writing for the court in Keller v. State Bar of California, said the case was analogous to a 1977 ruling that public employees could not be forced to pay agency shop fees to support political and ideological causes of the union that were not related to collective bargaining.

Rehnquist acknowledged that it "will not always be easy" to determine "precisely where the line falls" between activities for which the bar may use compulsory dues and those which are not allowed.

In a second opinion yesterday, the court said Illinois bar authorities violated a state lawyer's First Amendment rights when they sought to discipline him for accurately describing himself on his letterhead as a "certified civil trial specialist" by "the National Board of Trial Advocacy."

Edwardsville, Ill., lawyer Gary E. Peel was censured by the Illinois Supreme Court for advertising the certification -- which requires extensive trial experience -- on his letterhead. Bar officials complained that consumers might be misled into believing that Peel was better qualified than other lawyers or that the state had certified him as a specialist.

In a fractured ruling, a majority of the justices -- John Paul Stevens, William J. Brennan Jr., Harry A. Blackmun and Anthony M. Kennedy, and Thurgood Marshall in a concurring opinion -- agreed the letterhead "was neither actually or inherently misleading."

But a separate majority -- Marshall and the four dissenters -- said the letterhead was at least potentially misleading. They appeared willing to give states leeway to enact regulations short of a total ban to ensure that the public is not confused.

In a dissenting opinion joined by Rehnquist and Justice Antonin Scalia, Justice Sandra Day O'Connor defended the action of bar authorities and said the claim of certification was "inherently likely to deceive the public," even though it was true. Justice Byron R. White dissented separately.