QAZ QAZ - 1 month ago 10
HTML Question

Are nested HTML comments possible?

as per the title; is it possible to have nested comments in valid HTML? see the example below...

<p>some text</p>

<!-- comment 1

<p>commented out html</p>

<!-- comment 2

// are nested html comment allowed?

end of comment 2 -->

<p>more commented out html</p>

end of comment 1 -->

<p>some more text</p>


It appears not, does anybody know how I could get nested comments to work?

Thanks in advance.

Answer

When you nest a comment, replace "--" with "- -". When you un-nest, reverse the procedure. It's not the <!-- that is forbidden but the --.

Comments