A definition like Tangent is a line that only touches the curve at a single point, is not quite right. It can be seen as the property of the tangent but not the definition.
I don’t have a formal definition too but a good one.
Let’s start from here.
What is a slope of a line y=f(x)? It is change in y with respect to change in x.

For a line, the rate of change is constant. But in the case of a curve y = f(x), the rate of change in y with respect to x is not constant (that’s why it is a curve, else it would have been a straight line)
So, how do we find the rate of Change for a curve?
Well, we would need Tangent. Just take two points on the curve and join them with a straight line. And you can calculate the average rate of range between those two points same as for the above line.

But what if we want to know the instantaneous rate of change at a particular point only?
We use limits for this purpose. Think of it like that.
Bring the two points from the above diagram closer and closer and closer until they are the kind of same but with an infinitesimally small distance between them.
So now, when you connect these two points and draw a straight line. That is your tangent.
In your first diagram, you are not taking the two points on the curve. You can’t actually draw a unique line with a single point. You need at least two. And in your case, the second point is not on the curve but outside. Your line is not showing the rate of change in y with respect to change in x. So just because it is touching the curve at one point doesn’t make it tangent.
If seen from the limits perspective, the tangent is not actually touching at one point but two. But the distance between them tends to be zero which means the distance is getting closer and closer to zero. Something like 0.00000000…001.
Joining the lines gives us the tangent. So then It doesn’t matter if it touches the complete curve at one point or two or ten.
Given above a graph for same. Try changing the value of “h” on that page and see yourself how you get a tangent.
I think I made it clear. if not please point out the line. I’d try to explain even better.
But always try to understand what anything is than to follow the rules directly.