Labs ICT
Pro Login

Comments

Commenting in EJS templates.

EJS Comments Syntax

EJS has its own comment syntax using <%# and %>. These comments are stripped out during rendering — they never appear in the final HTML.


<%# This is an EJS comment %>
<p>This paragraph will render.</p>
    

Comments are useful for leaving notes about why a section exists or what a complex expression does.

Single-Line vs Multi-Line

EJS comments are single-line by default. If you need a longer comment, just use multiple comment tags on consecutive lines.


<%# This is a longer comment %>
<%# that spans multiple lines %>
<%# for better readability %>
<p>Content starts here.</p>
    

Keep comments short and to the point. If you need extensive documentation, put it in a separate file.

When to Use EJS Comments

EJS comments are best for marking sections of your template or explaining non-obvious logic. They're removed before the HTML reaches the browser.


<%# Header section - rendered on all pages %>
<header>
  <h1>My Website</h1>
</header>

<%# Main content area %>
<main>
  <p>Welcome!</p>
</main>

<%# Footer hidden on mobile via CSS %>
<footer>
  <p>© 2026</p>
</footer>
    

Use them to label sections, explain workarounds, or leave reminders for your future self.

Comments vs Code Documentation

EJS comments are different from JavaScript doc comments or HTML comments. HTML comments (<!-- -->) stay in the rendered output. EJS comments do not.


<%# This comment is invisible to users %>
<!-- This comment IS visible in page source -->

<p>Only the EJS comment is safe for internal notes.</p>
    

If your note contains sensitive information like logic decisions or TODOs, always use EJS comments so they stay private.

Try it Yourself →