The ideal magnetohydrodynamic (MHD) stability of the tokamak edge is analyzed, with particular emphasis on radially localized instabilities; it is proposed that these are responsible for edge pressure gradient limits and edge localized modes (ELMS). Data and stability calculations from DIII-D [to appear in Proceedings of the 16th International Conference on Fusion Energy, Yokohama (International Atomic Energy Agency, Vienna, 1998), Paper No. IAEA-F1-CN-69/EX8/ 1] tokamak equilibria indicate that two types of instability are important: the ballooning mode (driven by pressure gradient) and the peeling mode (driven by current density). The characteristics of these instabilities, and their coupling, are described based on a circular cross-section, large aspect ratio model of the tokamak equilibrium. In addition, preliminary results are presented from an edge MHD stability code which is being developed to analyze general geometry tokamak equilibria; an interpretation of the density threshold to access the high-confinement-mode (H-mode), observed on COMPASS-D [Plasma Phys. Controlled Fusion 38, 1091 (1996)] is provided by these results. Experiments on DIII-D and the stability calculations indicate how to control ELMs by plasma shaping.