DEV Community

Cover image for 8 other ways to comment in HTML
Matt Ellen
Matt Ellen

Posted on

8 other ways to comment in HTML

If you're someone who's found themselves knee deep in HTML, you'll know that even this so called "not a programming" language has comments. They're pretty obvious:

<!-- this is a comment in HTML -->
Enter fullscreen mode Exit fullscreen mode

That's it. There's no other way to write comments in HTML. Well...

Anakin & Padme meme

OK, so officially <!-- comment --> is how comments should be written. But the specification will turn your HTML into a comment at the drop of a hat.

Let's have a look at the many and varied ways that parser errors should result in comments!

1. Not dashing enough

<!--> and <!--->

2. Too much bang for your buck

<!-- comment --!>

3. My hyphen key broke

<! whatever or <! whatever > (yes, it can even end with the EOF)

4. You can question my comments

<?whatever etc. or <?whatever etc.>

5. I don't think you should be here

<![CDATA[whatever]]> (this only applies in "non-foreign" content)

6. It started so well

<!-- comment (EOF in comment)

7. This script is too short

<script><!-- comment (EOF in script)

8. Learn the rules of tag

<666></666> (opening part is treated as text, the closing part is a comment)

On top of all those non-comment comments, a final extra quirk: the second --> in <!-- <!-- I wish I could nest comments --> --> is treated as mark up!

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.