Apartheid had existed in unofficial forms in South Africa for years before it became law in the mid-twentieth century. A significant precursor to apartheid was the passage of the Glen Grey Act of 1894. This law spelled the end of communal land rights in the colony. Mass migrations of Black South Africans from their tribal lands ensued. In an attempt to provide a solution to the thousands of South Africans without their own land rights, the Native Land Act established large tribal reservations beginning in 1913. These two laws created the basic legal framework that could dictate how people could be legally excluded from certain areas based on race.
As South Africa began industrializing in the early twentieth century, many Black South Africans relocated from rural areas to urban ones. This worried many white urbanites, as most cities had been historically white. Furthermore, because the South African government did little to aid the Black population in cities, overcrowding and unsanitary living conditions ensued. Black South Africans began to grow more politically active as they sought more protections from the government. This further worried the white population, as they feared that they were losing their own political power.
Urban Afrikaners, in particular, felt threatened by this new outspoken Black population in their midst. The National Party was founded, in part, in response to this in 1914. Over the next several decades, this party rose in prominence as the party of white supremacy in South Africa. The National Party won a majority of seats in Parliament in 1948. As a result, over the next several years, they were able to draft and pass legislation codifying racial segregation under apartheid.