The slope of a line is defined as the rate of change on the vertical axis, divided by the rate of change on the horizontal axis, Δy/Δx. So for a horizontal line, the rate of change on the y axis is zero, this means that it's slope will be 0/Δx and for vertical line, x-axis does not change, which make the denominator 0 Δy/0.