Browsers will try their best to render invalid markup. They really are quite tolerant, nowadays. But it is still invalid code and will not pass the W3C validator check.
If you were to write some behavior behind the page (script) you would get unexpected results. That is why it is best to write all the HTML first, then validate it, and only then start to add behaviors. I know you might not be there yet, so just keep this in the back of your mind.
The reason your page passes the exercise is because the lesson checker isn't looking for validation errors.