Complete reference for Pugz template syntax.
Indentation defines nesting. Default tag is div.
div
h1 Title
p ParagraphOutput:
<div><h1>Title</h1><p>Paragraph</p></div>Shorthand syntax using . for classes and # for IDs.
div#main.container.active
.box
#sidebarOutput:
<div id="main" class="container active"></div>
<div class="box"></div>
<div id="sidebar"></div>a(href="/link" target="_blank") Click
input(type="checkbox" checked)
button(disabled=false)
button(disabled=true)Output:
<a href="/link" target="_blank">Click</a>
<input type="checkbox" checked="checked" />
<button></button>
<button disabled="disabled"></button>Boolean attributes: false omits the attribute, true renders attr="attr".
p Hello Worldp
| Line one
| Line twoscript.
console.log('hello');
console.log('world');<p>Passed through as-is</p>p Hello #{name}
p= variablep Hello !{rawHtml}
p!= rawVariablep This is #[em emphasized] text
p Click #[a(href="/") here] to continueif condition
p Yes
else if other
p Maybe
else
p Nounless loggedIn
p Please loginif status == "active"
p Activeeach item in items
li= itemeach val, index in list
li #{index}: #{val}each item in items
li= item
else
li No itemseach val, key in object
p #{key}: #{val}each friend in friends
li #{friend.name}
each tag in friend.tags
span= tagcase status
when "active"
p Active
when "pending"
p Pending
default
p Unknownmixin button(text)
button= text
+button("Click me")mixin button(text, type="primary")
button(class="btn btn-" + type)= text
+button("Click me")
+button("Submit", "success")mixin card(title)
.card
h3= title
block
+card("My Card")
p Card content heremixin list(id, ...items)
ul(id=id)
each item in items
li= item
+list("mylist", "a", "b", "c")mixin link(href, text)
a(href=href)&attributes(attributes)= text
+link("/home", "Home")(class="nav-link" data-id="1")doctype html
html
head
title= title
block styles
body
block content
block scriptsextends layout.pug
block content
h1 Page Title
p Page contentblock append scripts
script(src="extra.js")
block prepend styles
link(rel="stylesheet" href="extra.css")include header.pug
include partials/footer.pug// This renders as HTML commentOutput:
<!-- This renders as HTML comment -->//- This is a silent commentColon for inline nesting:
a: img(src="logo.png")Output:
<a><img src="logo.png" /></a>Explicit self-closing with /:
foo/Output:
<foo />Void elements (br, hr, img, input, meta, link, etc.) are automatically self-closing.
doctype htmlOutput:
<!DOCTYPE html>