We prove some higher dimensional generalizations of the slope inequality originally due to G. Xiao, and to M. Cornalba and J. Harris. We give applications to families of KSB-stable and K-stable pairs, as well as to the study of the ample cone of the moduli space of KSB-stable varieties. Our proofs relies on the study of the Harder-Narasimhan filtration, and some generalizations of Castelnuovo's and Noether's inequalities.