Band alignment of 2D carbon–boron nitride alloys informs routes toward applications in photocatalysis and electronics.