In Santa Clara County, jail guards sent text messages using racial slurs to describe African Americans, Jews and Vietnamese Americans.
In San Francisco, as many as 19 police officers have been implicated in a texting scandal involving racial and homophobic insults.
And a top Los Angeles County Sheriff's Department official recently resigned amid an outcry over emails he forwarded that mocked Muslims, blacks, women and others.
Recent controversies over emails and texts show how the intense scrutiny currently faced by police officers has extended beyond their actions on patrol and into communications that some thought were private.
The shift has come as police departments nationwide are trying to address the attitudes of officers before problems on the streets arise. Among other things, agencies have adopted training that examines implicit biases and have pushed to hire more minority recruits.
And after a generation of community policing and outreach to minority communities, such comments — even in emails and text messages — are indefensible to many police officers.
"I've seen a serious change in the last 10 years of my career," said Alan Chu, a sheriff's sergeant at the Crescenta Valley Station who moved to the U.S. from Hong Kong when he was a child. "I think it's a different generation, to be honest, as we hire more people and the sensitivities increase and some of the older guys have retired."
The recent focus on how police deal with minority residents is also playing a role. The shooting of a black teenager in Ferguson, Mo., by a white police officer in 2014 helped spark a debate over police use of force, particularly against African American men. A U.S. Justice Department investigation unearthed numerous racist emails by two of the city's police supervisors and a court clerk.
One email depicted President Obama as a chimpanzee. Others compared minority welfare recipients to dogs and contained insensitive comments about Muslims.
Such communications show deep-seated prejudices that are unacceptable in law enforcement, said Kathy Spillar, who oversees the National Center for Women and Policing.
"The jokes reveal an underlying attitude that can never be tolerated," Spillar said. "If you're saying this stuff, guess what? You're biased."
Many police officials insist that the problem of racist jokes and other exchanges is far from unique to law enforcement, reflecting broader societal issues. Still, the revelations have put officers on notice that their personal conversations could become public, embarrass their employers and cost them their jobs.
"I think we will continue to see things like this, not happening more often, but becoming more visible," said Seth Stoughton, a former police officer who is now a professor at the University of South Carolina School of Law. "What would surprise me is if an agency just accepted it and didn't do anything about it."
Stoughton said that some officers adopt a dangerous form of humor that employs racial stereotypes as a way of coping with the violence they encounter on the job, much as some soldiers sometimes feel the need to dehumanize the enemy.
In the 1980s and early 1990s, LAPD officers were caught sending racist and sexist messages not via email but through their patrol car computers.
On the same day as the 1991 beating of Rodney King, one of the LAPD officers involved sent a message to a colleague describing a domestic violence call at a black family's home as "right out of Gorillas in the Mist."
In those days, some law enforcement officers said, such sentiments were more prevalent, and those who espoused them were less likely to be disciplined.
In Glendale, greater diversity among police officers has meant that making fun of minorities would be making fun of their own.
"We have Armenian officers, Korean officers, black officers, females, and so to say that these types of jokes happen, it's in the culture, I would disagree," said Sgt. Robert William.
A very different brand of cop humor — making light of death — is acceptable as long as it stays between officers, some said, and can be a needed release to move past the tragedies they witness.
"What goes on in a radio car stays there," said Bob Olmsted, a retired sheriff's commander who started with the department in 1978 and remembers joking about a person whose head had been blown off. "What's said over the public domain, in emails that can be easily forwarded, that's a big difference."
Last week, San Francisco's public defender, Jeff Adachi, sharply criticized three city police officers for text messages they exchanged referring to minorities as "barbarians" and "cockroaches" and using racial slurs. The messages were the latest in a growing list of racist emails and texts traded among the city's officers, resulting in the dismissal of 13 pending criminal cases.
"That's the kind of mentality that tells you it's OK to shoot, OK to kill, OK to arrest" people of color, Adachi told reporters.
In the Santa Clara County jails, guards exchanged text messages applauding violence against blacks, using racial slurs and sharing images of a Nazi swastika and a lynching, the San Jose Mercury News reported.
The emails that led Tom Angel to step down as the Los Angeles County's sheriff's chief of staff were sent in 2012 and 2013, when he was the No. 2 police official in Burbank.
"I took my Biology exam last Friday," said one of the emails, which The Times obtained from the city of Burbank under the state's public records law. "I was asked to name two things commonly found in cells. Apparently 'Blacks' and 'Mexicans' were NOT the correct answers."
Another email ridiculed concerns about the racial profiling of Muslims as terrorism suspects. A third included the subject line "How dumb is dumb?" and listed 20 reasons "Muslim Terrorists are so quick to commit suicide," including "Towels for hats," "Constant wailing from some idiot in a tower" and "You can't wash off the smell of donkey."
Four of the emails contained strings of jokes that Angel received and then forwarded. A fifth email was a short dialogue between Angel and another Burbank police official in which Angel asked what he called a trivia question: "How many virgins do Muslims get in heaven?"
After initially saying he had no immediate plans to discipline Angel, Sheriff Jim McDonnell announced over the weekend that he had accepted his chief of staff's resignation.
McDonnell has agreed to randomly audit the emails of sheriff's employees for offensive content after some civil rights leaders called on him to do so.
With increased scrutiny coming from within police departments and the public, officers need to realize that the audience for their jokes may expand beyond their colleagues, said Derek Hsieh, a veteran of the Anchorage Police Department who is now executive director for the union that represents L.A. County sheriff's deputies.
As more agencies adopt body cameras to record interactions with the public, casual conversations between officers may end up on tape, too.
"With the increasing amount of audio and video recording, you have to be extremely careful that your comments will be taken and not judged by other cops in the context of that circumstance, but by the public at large," Hsieh said.