Thick GaN layers as well as AlGaN/GaN and AlN/GaN heterostructures grown by metalorganic vapor phase epitaxy have been photoelectrochemically (PEC) etched in various dilute electrolytes, and bandgap-selective etching has been demonstrated in heterostructures. This result is a significant step forward in the fabrication of group III-nitride devices and one-dimensional photonic bandgap (PBG) structures in the deep UV. Based on initial results from thick GaN layers, a method was developed to achieve self-stopping selective etching of thin GaN layers in AlGaN/GaN and AlN/GaN heterostructures. Selective PEC etching requires the use of a suitable light source with photon energies larger than the bandgap of GaN, but smaller than that of AlGaN or AlN, thus enabling selective hole generation in the GaN layers to be etched. Additionally, it is imperative to use an electrolyte that supports PEC etching of GaN without chemically etching AlGaN or AlN.