Most studies use survey data to study peoples prejudiced views. In a digitally connected world, research is needed on out-group sentiments expressed online. In this study, we show how one can elaborate on existing sociological theories (i.e. group threat theory, contact theory) to test whether anti-immigrant sentiments expressed on Twitter are related to sociological conditions. We introduce and illustrate a new method of collecting data on online sentiments, creating a panel of 28,000 Twitter users in 39 regions in the United Kingdom. We apply automated text analysis to quantify anti-immigrant sentiments of 500,000 tweets over a 1-year period. In line with group threat theory, we find that people tweet more negatively about immigrants in periods following more salient coverage of immigration in the news. We find this association both for national news coverage, and for the salience of immigration in the personalized set of outlets people follow on Twitter. In support of contact theory, we find evidence to suggest that Twitter users living in areas with more non-western immigrants, and those who follow a more ethnically diverse group of people, tweet less negatively about immigrants.