Beryllium and magnesium have abnormally small size as compared to alkaline earth metals (because of diagonal relationship with lithium and aluminium respectively-same charge to size ratio). Because of which, the electrons are more strongly held as compared to alkaline earth metals. the metals give out flame colour when the electrons undergo transition on providing energy. on coming back to their original levels, they emit specific wavelengths. since, these transitions are not possible in case of Be and Mg, they do not impart characteristic wavelength to flame.