As biodiversity declines with anthropogenic land-use change, it is increasingly important to understand how changing biodiversity affects infectious disease risk. The dilution effect hypothesis, which points to decreases in biodiversity as critical to an increase in infection risk, has received considerable attention due to the allure of a win-win scenario for conservation and human well-being. Yet some empirical data suggest that the dilution effect is not a generalizable phenomenon. We explore the response of pathogen transmission dynamics to changes in biodiversity that are driven by habitat loss using an allometrically scaled multi-host model. With this model, we show that declining habitat, and thus declining biodiversity, can lead to either increasing or decreasing infectious-disease risk, measured as endemic prevalence. Whether larger habitats, and thus greater biodiversity, lead to a decrease (dilution effect) or increase (amplification effect) in infection prevalence depends upon the pathogen transmission mode and how host competence scales with body size. Dilution effects were detected for most frequency-transmitted pathogens and amplification effects were detected for density-dependent pathogens. Amplification effects were also observed over a particular range of habitat loss in frequency-dependent pathogens when we assumed that host competence was greatest in large-bodied species. By contrast, only amplification effects were observed for density-dependent pathogens; host competency only affected the magnitude of the effect. These models can be used to guide future empirical studies of biodiversity-disease relationships across gradients of habitat loss. The type of transmission, the relationship between host competence and community assembly, the identity of hosts contributing to transmission, and how transmission scales with area are essential factors to consider when elucidating the mechanisms driving disease risk in shrinking habitat. This article is part of the themed issue 'Conservation, biodiversity and infectious disease: scientific evidence and policy implications'.