william44isme william44isme - 6 months ago 12
HTML Question

Validator, </a> tag: "End tag a violates nesting rules"

I ran my website in the w3 validator and got this error...

Line 16, Column 4: End tag a violates nesting rules.

</a>


What is the problem? I worked hard to write good markup and only got 2 errors, the other error I fixed, but this one I just can't work out...

Answer

It means that you have mis-matched tags.

For example, the following code will throw the error described:

<a href=''><b>Some text</a></b>

Given that you made a point to state that you'd tried to write good markup and that you don't have any other errors, I guess you know that already, so what could be causing it.

My guess is that you've got a tag which isn't being closed properly inside your <a> tag.

For example, in the example I gave above, you might have the closing </b> tag in the right place, but maybe have a typo with it that stops it being recognised as a closing tag - eg maybe missing the slash? That would be the most plausible, and easy to miss.

Or another example -- maybe you've got code like this:

<a href=''><img src='pic.jpg'></a>

In an HTML document, the above code is perfectly valid. However, if you've specified your <DOCTYPE> as xhtml it is invalid, because in xhtml all tags need to be closed, and the <img> above isn't. It would need a closing slash added to it like this:

<a href=''><img src='pic.jpg' /></a>

My guess is that your error is something along these lines.

You haven't shown us the code that is generating the errors, so I'm shooting in the dark a bit here, but that is my guess.

I would also say that while the W3C's validator is an excellent resource, if you're using a decent IDE to write your code, the code editor should highlight any syntax errors like this for you while you're writing the code. That would make it very easy to see the problem. Even some browsers' View Source feature will show you syntax highlighting which may reveal the problem.

Comments