Doctype

  1. doctype html
  1. <!DOCTYPE html>

Doctype Shortcuts

There are shortcuts for commonly used doctypes:

  • doctype html
  1. <!DOCTYPE html>
  • doctype xml
  1. <?xml version="1.0" encoding="utf-8" ?>
  • doctype transitional
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  • doctype strict
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  • doctype frameset
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
  • doctype 1.1
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  • doctype basic
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">
  • doctype mobile
  1. <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">
  • doctype plist
  1. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

Custom Doctypes

You can also use your own literal custom doctype:

  1. doctype html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN"
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN">

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.

  1. var pug = require('pug');
  2. var source = 'img(src="foo.png")';
  3. pug.render(source);
  4. // => '<img src="foo.png"/>'
  5. pug.render(source, {doctype: 'xml'});
  6. // => '<img src="foo.png"></img>'
  7. pug.render(source, {doctype: 'html'});
  8. // => '<img src="foo.png">'