Objective. Simultaneous electroencephalography and functional magnetic resonance imaging recording (EEG-fMRI) has been widely used in neuroscientific and clinical research. The artifacts in the recorded EEG resulting from rapidly switching magnetic field gradients are usually corrected by average-artifact subtraction (AAS) due to their repetitive nature. But the performance of AAS is often disrupted by altered artifact waveforms across epochs, notably due to head motion. Approach. Here, a method is proposed to make use of the known MR sequence gradient waveforms for a direct modelling of gradient artifacts. After accounting for filtering effects on the gradient artifacts, a continuous modulation of the gradient waveforms superimposed on the EEG signal is obtained. Main results. Although a moving AAS template can adjust to slow drifts in gradient artifact variation, it fails to adapt to abrupt motion, resulting in residual noise. We demonstrate how this modelling approach can reduce motion-affected gradient artifacts without distorting the underlying neuronal signals. Moreover, the method provides useful head motion information highly correlated with motion tracked by an optical camera. Significance. Our work provides a novel way to improve gradient artifact removal in EEG-fMRI, and shows a potential to detect head motion without requiring additional hardware.