there are several compounds that give red onions their colour. they are mostly derivatives of cyanidin. the notable red colour of cyanidin varies with ph, going from red at acidic ph's through violet in mid range to blue for alkili. the natural ph of onion is between 5 and 6 (different varieties have different ph ranges) but during cooking, some volatile sulphur containing compounds responsible for lowering the ph are evaporated off. this raises the ph, thus altering the colour. this effect combined with the clarification of the onion flesh (white and opaque when raw) makes the cooked onion appear grey.