Domain boundary formation in development involves sorting of different types of cells into separate spatial domains. The segment boundary between tarsus 5 (Ta5) and the pretarsus (Pre) of the Drosophila leg initially appears at the center of the leg disc and progressively sharpens and expands to its final position, accompanied by down-regulation of the cell recognition molecule Capricious and Tartan and cell displacement from Ta5 to Pre across the boundary. Capricious and Tartan are controlled by transcription factor Bar and Al, and their loss of function leads to reduction of cell affinity to wild type neighbors and cell displacement activities. In addition, although the mutant cells formed Ta5/Pre boundary, its progression and sharpening were compromised. Cells overexpressing Capricious or Tartan became invasive within Ta5 and Pre, sometimes escaping the compartmental restriction of cell movement. Dynamic spatiotemporal regulation of cell affinity mediated by Capricious and Tartan is a key property of refinement of the Ta5/Pre boundary.