The gravitational potential energy (U) at some height h is equal to the amount of work required to take the object from ground to that height h with constant velocity. Let us consider a body of mass m being moved from ground to the height h against the gravitational force as shown.
The gravitational force \(\vec F_g\) acting on the body is,\(\vec F_g\)= \(-mg \hat j\) (as Gravitational potential energy the force is in y direction, unit vector \(\hat j\) is used). Here, negative sign implies that the force is acting vertically downwards. In order to move the body without acceleration (or with constant velocity), an external applied force \(\vec F_a\) , equal in magnitude but opposite \(\vec F_g\) to that of gravitational force has to be applied on the body i.e., \(\vec F_a\) = -\(\vec F_g\) .
This implies that \(\vec F_a\) = \(+mg \hat j\) . The positive sign implies that the applied force is in vertically upward direction. Hence, when the body is lifted up its velocity remains unchanged and thus its kinetic energy also remains constant. The gravitational potential energy (U) at some height h is equal to the amount of work required to take the object from the ground to that height h.
Since the displacement and the applied force are in the same upward direction, the angle between them, θ = 0°. Hence, cos 0° = 1 and \(|\vec F_a|\) = mg and \(|d \vec r|\) = dr.