We investigated bandgap engineering of spinel-structured MgB
2O4 (B = Al, Ga, In) alloys. The trend of bandgap change was tunable from approximated 7.8 to 3.6 eV by substituting group III cation atoms in MgB
2O4. To evaluate the doping possibility, we have calculated the natural band alignment and doping pinning energy of the normal and inverse spinel structures of MgB
2O4 alloys. The calculated doping pinning energies show that spinel-structured MgB
2O4 alloys can potentially control the electron concentration, but hole doping is difficult. Our computational results are expected to provide new insights into the doping control of ultra-wide bandgap semiconductors.