Mixins allow you to create reusable blocks of Pug.

They are compiled to functions and can take arguments:

Mixin Blocks

Mixins can also take a block of pug to act as the content:

Mixin Attributes

Mixins also get an implicit attributes argument taken from the attributes passed to the mixin:


The values in attributes by default are already escaped so you should use != to avoid escaping them a second time (see also unescaped attributes).

You can also use mixins with &attributes:


The syntax +link(class="btn") is also valid and equivalent to +link()(class="btn") since Pug try to detect if parentheses contents are attributes or arguments but we encourage you to use the second syntax as you pass explicitly no arguments and you ensure the first parenthesis is the arguments list.

Rest Arguments

You can write mixins that take an unknown number of arguments using the “rest arguments” syntax. e.g.