What's the reason we wrap input in labels?

I am currently doing the basic HTML tutorials. Here we learn to wrap input elements inside label elements, but as far as I can see, it isn’t explained why this is done. What function does the label elements have in this case?

It associates an input field with its descriptive text. This is an accessibility issue for software, but it is also often leveraged by libraries to help your forms look and behave in a way that is optimal for all users.

When implementing forms using traditional HTML form-related elements, it is important to provide labels for controls, and explicitly associate a label with its control. When a screen reader user navigates a page, the screen reader will describe form controls. Without a direct association between the control and its label, the screen reader has no way of knowing which label is the correct one.

Sorry for replying this late, but thanks for your answer, I understand the meaning behind it now.

I’m glad I could help. Happy coding!