It's easy to call them racists, but you can make an argument that they were voting out of self-interest.
It is true that not all Brexiteers are racists, but all racists voted for Brexit.
Large numbers of Eastern European EU citizens migrated to the UK seeking both employment and a strong social safety net (including free healthcare).
Because, of course, there was no equivalent of the National Health Service in the countries where these people came from. As has been noted elsewhere, the free movement of people within the EU has been largely been replaced by immigration from the Indian subcontinent. A triumph of unintended consequences.
The situation for poorer working class Brits was a little different, who experienced wage stagnation and ever-increasing rents at the low end of the market.
The working class had been experiencing wage stagnation, poor education, housing and environment for decades before the referendum. It can be laid at the feet of Thatcher, who gutted the job market and social housing.