Forced and free transverse vibrations of a nanobeam under a moving load are investigated in this work. Through the strain gradient theory, high‐order governing partial differential equations of the nanobeam are established by the extended Hamilton's principle, which incorporates its material, geometrical, and nanoscale parameters. The dynamic response of the nanobeam is obtained from spatially discretized equations via the Galerkin's method. Effects of material, geometrical, and nanoscale parameters on the forced transverse vibration of the nanobeam are discussed. Results show that material and nanoscale length parameters play a very important role in determining the amplitude of the forced transverse vibration of the nanobeam. The cancellation velocity of the moving load is determined from the rigorous initial displacement and velocity of the free transverse vibration of the nanobeam, and an approximate expression of the cancellation velocity is presented by means of its first‐mode response. Effects of geometrical and nanoscale parameters on the cancellation velocity are also discussed. It is shown that amplitudes of all modal responses of the nanobeam are not simultaneously equal to zero at the cancellation velocity.