Biologists have devoted much attention to assortative mating or homogamy, the tendency for sexual species to mate with similar others. In contrast, there has been little theoretical work on the broader phenomenon of homophily, the tendency for individuals to interact with similar others. Yet this behaviour is also widely observed in nature. Here, we model how natural selection can give rise to homophily when individuals engage in social interaction in a population with multiple observable phenotypes. Payoffs to interactions depend on whether or not individuals have the same or different phenotypes, and each individual has a preference that determines how likely they are to interact with others of their own phenotype (homophily) or of opposite phenotypes (heterophily). The results show that homophily tends to evolve under a wide variety of conditions, helping to explain its ubiquity in nature.