We investigated time-resolved ultraviolet–visible (UV–vis) light absorbance to identify the formation behaviour of formaldehyde (HCHO) and hydroxyl (OH) within the wavelength range of 280–400 nm in a homogeneous charge compression ignition (HCCI) engine fuelled with dimethyl ether (DME). The time-resolved HCHO and OH profiles at different initial pressures showed that HCHO absorbance increased in the low-temperature reaction (LTR) and thermal-ignition preparation (TIP) regions and decreased gradually as the combustion approached the high-temperature reaction (HTR) region. At higher intake pressures, HCHO absorbance decreased and OH absorbance increased. The time-resolved absorbance spectra of HCHO, with peaks at 316, 328, 340, and 354 nm for all combustion cycles, were evaluated and it was found that average absorption at 328 nm was slightly higher than at 316, 340, and 354 nm. For knocking combustion cycles, the absorbance of HCHO in the LTR region was high for cycles with low knock intensity and low for cycles with high knock intensity, showing a high level of OH absorbance. Chemical kinetics analyses showed that for different fuel/oxidiser ratios, initial O2 concentration and intake temperature had no effect on in-cylinder temperatures in the LTR or TIP regions. However, they did have significant effects on HTR combustion. In-cylinder temperature in the LTR region had less effect on HCHO and H2O2 formation than pressure.