Doctype Shortcuts

There are shortcuts for commonly used doctypes:

doctype html
<!DOCTYPE html>
doctype xml
<?xml version="1.0" encoding="utf-8" ?>
doctype transitional
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
doctype strict
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
doctype frameset
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "">
doctype 1.1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "">
doctype basic
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "">
doctype mobile
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "">
doctype plist
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">

Custom Doctypes

You can also use your own literal custom doctype:

Doctype Option

In addition to being buffered in the output, a doctype in Pug can affect compilation in other ways. For example, whether self-closing tags end with /> or > depends on whether HTML or XML is specified. The output of boolean attributes may be affected as well.

If, for whatever reason, it is not possible to use the doctype keyword (e.g., just rendering HTML fragments), but you would still like to specify the doctype of the template, you can do so via the doctype option.

var pug = require('pug');

var source = 'img(src="foo.png")';

// => '<img src="foo.png"/>'

pug.render(source, {doctype: 'xml'});
// => '<img src="foo.png"></img>'

pug.render(source, {doctype: 'html'});
// => '<img src="foo.png">'