The widget below shows a straight line in three dimensions, passing through the origin. Try moving the endpoint of the line around using the yellow dot $(\textcolor{yellow}{\bullet})$, $P$, and see how the angle with the three axes, and their corresponding cosine value changes.
--------- Reference to widget: 4caef3fd-04c4-418a-911e-e55d149673cc ---------
The widget above showed a line passing through the origin. Here we can consider any random line, passing through $M (x_1, y_1, z_1)$, and having direction cosines of $\cos \alpha$, $\cos \beta$ and $\cos \gamma$ respectively.
If we choose any other point, $P (x, y, z)$, on this line, and draw a cuboid with $MP$ as the diagonal then $MP = \sqrt{(x - x_1)^2 + (y - y_1)^2 + (z - z_1)^2}$, and the direction cosines will be:
represent the line passing through the point $(x_1, y_1, z_1)$ and having direction cosines of $\cos \alpha$, $\cos \beta$ and $\cos \gamma$ with the $X$, $Y$ and $Z$ axes respectively.
Conventionally, the direction angles of a line with the positive $x$, $y$ and $z$ axes are denoted using $\alpha$, $\beta$ and $\gamma$ respectively, and the three direction cosines, $\cos \alpha$, $\cos \beta$ and $\cos \gamma$ are represented using $l$, $m$ and $n$ respectively.