In the United States, segregation started in the 1840s. Segregation was not legal until 1896, however, when the ruling came in Plessy v. Ferguson from the U.S. Supreme Court.
After slavery was abolished, churches, schools and other establishments responded by enforcing segregation. In a response to this segregation, the Civil Rights Act of 1875 passed which forbid it in establishments. Two years later the Compromise of 1877 was put into place and this ended the Reconstruction Era, which in turn, put an end to segregation being illegal. Segregation continued and the Supreme Court case Plessy v. Ferguson ruled that the Constitution did not prevent private establishments from segregating patrons based on race.