Structurally complex habitats tend to contain more species and higher total abundances than simple habitats. This ecological paradigm is grounded in first principles: species richness scales with area, and surface area and niche density increase with three-dimensional complexity. Here we present a geometric basis for surface habitats that unifies ecosystems and spatial scales. The theory is framed by fundamental geometric constraints between three structure descriptors—surface height, rugosity and fractal dimension—and explains 98% of surface variation in a structurally complex test system: coral reefs. Then, we show how coral biodiversity metrics (species richness, total abundance and probability of interspecific encounter) vary over the theoretical structure descriptor plane, demonstrating the value of the theory for predicting the consequences of natural and human modifications of surface structure.