Corporations generally don’t like getting involved in politics. They spend a fortune on lobbying, but they don’t want to be seen as overtly partisan for fear of offending half their potential customers. So why are so many big companies lining up in support of LGBT rights?

There are a couple of factors at play. To start, it’s been expected for a while now that companies have in place corporate social responsibility programs, meaning they adopt formal policies to demonstrate that they’re good citizens of their communities. “With the corporate social responsibility revolution, now it’s OK for companies to take sides on things like environmental change and human rights,” says Frank Dobbin, a sociologist at Harvard University.

Still, Dobbin notes, corporations don’t like to go looking for trouble. They tend to stay on the sidelines of contentious issues, waiting until there’s a bandwagon they can jump on. That may have happened with the push to end discrimination against gay and transgender individuals. Just as legalized discrimination against African-Americans is no longer acceptable, LGBT rights are fast becoming a given within certain circles -- the circles upper management tends to run in. “When you get to a certain elite social level, that analogy is entirely apt for them,” says Ryan Anderson, who researches social issues at the conservative Heritage Foundation. “It becomes a no-brainer.”

This dynamic is especially evident in centers of tech and finance. Some of the opposition to bills that restrict gay rights has come from locally based companies -- Monsanto in Missouri, Bank of America in North Carolina. But objections have also been raised from the outside by companies such as Apple, Disney and Deutsche Bank.

Tolerance has become an essential value to most millennials. Companies that want to target that enormous demographic as potential employees feel they must be seen as on board with gay rights. In 2002, only 3 percent of the Fortune 500 companies had policies in place to protect transgender employees, according to the Human Rights Campaign, a gay rights advocacy group. Now, more than 75 percent do. “They have younger employees who, even if they’re straight, would not be happy if they were supporting anti-gay laws,” says Mark Mizruchi, who studies corporate behavior at the University of Michigan. “How are they going to recruit a recent graduate of Harvard Business School to Atlanta or Charlotte if their states have relatively retrograde views on social issues?”

The principle applies to marketing as well. Researchers have found that today’s young adults are more inclined to buy products from a company such as Apple if they believe its values are in line with their own beliefs. Those between the ages of 26 and 35 are 21 percent more likely to buy from a company they feel reflects their values, according to Melissa Dodd at the University of Central Florida.

Other researchers have found that becoming associated with a cause can boost brand loyalty, including for companies that are seen as conservative. “Perhaps it is better in 2016 to be intensely loved by a few than inoffensive to many,” conclude Aaron Chatterji and Michael Toffel, professors at Duke and Harvard universities’ business schools, respectively.

There’s still a risk. Companies that get too far ahead of their customers on sensitive issues risk a backlash or even a boycott. But quite a few of the largest companies have concluded that support for gay rights -- along with other policies they are comfortable with, such as infrastructure spending and an open door for immigrants -- will be good for their bottom lines.