Nesting in HTML happens when you have one or more elements as the children of other HTML element. For example:
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. -->
<!-- this is invalid -->
The latter is what you have in your code, which is why its not working.