It doesn't = "infinity" [ this is what many calculators show ]
It would be better said that it is "undefined"
The tangent ratio is y / x
But, at 90°, y will = r, but x = 0......and since we cannot dvide by 0, then thr tangent is undefined at 90°
Here is the graph of y=tanx
You can see that as x tends to 90 degrees from below the tan of it approaches +infinity.
AND
as x tends to 90 from above x tends to - infinity.
So it is correct to say this
\(\displaystyle\lim_{x\rightarrow \infty^-}\;\;tanx=+\infty\\~\\ \displaystyle\lim_{x\rightarrow \infty^+}\;\;tanx=-\infty\\~\\ but\\ \displaystyle\lim_{x\rightarrow \infty}\;\;tanx=\text{undefined}\)