The slope of any line is the ratio of the change in y to the change in x, Δy/Δx. In a horizontal line, our rise is 0, which means that our numerator – and therefore our slope – is 0.
With a vertical line, our run is zero, which means that, since our denominator is 0, our slope is undefined.