Skip to content

Comments

Comment syntax depends on where the comment appears.

PositionSource-onlyRendered
Inside a tag// …, /* … */, {/* … */}, {// … }
Between child nodes// … (line start), {/* … */}, {// … }<!-- … -->
Outside markup// …, /* … */

A line that starts with // between child nodes is a source-only comment. It may not touch text content — next to a text line it is a compile error; use {// …} to comment or {"// …"} to render the slashes. Mid-line // is always literal text, and inside pre/textarea every // renders verbatim.

HTML comments

An HTML comment is rendered verbatim, including < and & in its text.

gsx
package views

component Layout(name string) {
	<div>
		<!-- header -->
		<h1>{ name }</h1>
		<!-- a < b -->
	</div>
}

Renders:

html
<div><!-- header --><h1>Ada</h1><!-- a < b --></div>

▶ Open in Playground

Comments inside a tag

Use Go-style line or block comments to annotate an element's attributes. Braced comment forms are also accepted there, and one braced group may hold several comments. These comments remain in the .gsx source but do not render.

gsx
package views

component Toggle(name string) {
	<input
		type="checkbox"
		// source-only note, never rendered
		id={name}
	/>
}

Renders:

html
<input type="checkbox" id="agree">

▶ Open in Playground

Comments between children

Use a braced comment between child nodes when the note should stay in source without appearing in the HTML.

gsx
package views

component Note() {
	<p>{/* hidden note */}Visible text</p>
}

Renders:

html
<p>Visible text</p>

▶ Open in Playground

Both {/* … */} and {// … } are source-only in child content.

gsx
package views

component Nav() {
	<nav>
		<a href="/">Home</a>
		// hidden from the HTML
		<a href="/about">About</a>
	</nav>
}

Renders:

html
<nav><a href="/">Home</a><a href="/about">About</a></nav>

▶ Open in Playground

Go comments outside markup

Outside markup, // and /* */ are ordinary Go comments. This includes package and import comments, helper functions, and comments inside a GoBlock.