We derive a class of mesoscopic virial equations governing energy partition between conjugate position and momentum variables of individual degrees of freedom. They are shown to apply to a wide range of nonequilibrium steady states with stochastic (Langevin) and deterministic (Nose--Hoover) dynamics, and to extend to collective modes for models of heat-conducting lattices. A generalised macroscopic virial theorem ensues upon summation over all degrees of freedom. This theorem allows for the derivation of nonequilibrium state equations that involve dissipative heat flows on the same footing with state variables, as exemplified for inertial Brownian motion with solid friction and overdamped active Brownian particles subject to inhomogeneous pressure.