DEV Community

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

Posted on

3 2

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!

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

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

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay