How to add comments in Svelte templates

How to avoid Svelte from presenting part of the template to the client

HTML comments are great for hiding elements on the page.

In HTML, this is how you add comments:

<!-- a comment here -->

You can also use it on blocks to hide multiple lines of HTML:


Note that this is still visible in the page source. The browser just hides it, but the comment is always visible.

You can use the same annotations in Svelte templates. However, with Svelte, you will not send the annotated part to the browser. This part has been completely deleted and only remains in your source file, which is not visible to the HTML generated in the page.

I think this is a positive thing.

Download mine for freeSlim Handbook

More subtle tutorials: