Nesting in HTML happens when you have one or more elements as the children of other HTML element. For example:
<div>
<button></button>
</div>
Here, the button is nested inside of the div. When one element is a child of another, Its opening and closing tag, both need to be inside of the parent element. If you start an element inside of one element and close it outside, that is not valid. for example:
<!-- this is valid. -->
<div>
<p></p>
</div>
<!-- this is invalid -->
<div>
<p>
</div>
</p>
The latter is what you have in your code, which is why its not working.