Free Online HTML to Pug Converter
The HTML to Pug Converter turns HTML markup into clean, indented Pug (formerly Jade) template syntax. Class and id shorthands, attributes, and nesting are all handled for you.
The indentation-sensitive output pairs with the HTML Formatter & Beautifier, and the JSX equivalent is produced by the HTML to JSX Converter. To strip the markup entirely rather than convert it, Strip HTML Tags is the tool.
How to use the HTML to Pug
- 1 Paste your HTML.
- 2 Convert. Tags become indentation, attributes move into parentheses, and ids and classes take the shorthand notation.
- 3 Check the output for elements where optional closing tags changed the nesting.
- 4 Copy the Pug template.
Reading and writing templates
Pug is at its best for the structural parts of a page, where the markup is inherently nested and the indentation mirrors the document tree. It is less comfortable for paragraphs of prose containing inline markup, because the syntax for mixing text and tags within a line is more verbose than the HTML it replaces.
That is a reasonable division in practice: build the layout in a template language where the structure is the point, and keep long-form content where it is readable as prose.
- Indentation defines nesting — consistency is required, not optional.
- `div.class#id` shorthand avoids attribute syntax.
- Multiple classes chain without separators.
- Mixing prose and inline markup is the awkward case.
Why Pug?
Pug removes closing tags and angle brackets, which makes templates shorter and easier to scan. Whitespace is significant, so this converter indents every level consistently for you.
Frequently asked questions
What makes Pug worth the indentation sensitivity?
It removes most of the punctuation. A div with a class and an id becomes a single short token, and there are no closing tags at all, which eliminates a whole class of error. The cost is that indentation carries meaning, so a mis-indented line changes the structure rather than merely looking untidy.
How does Pug handle text content?
Inline text follows the tag on the same line if short. Longer content goes in a piped block, where each line is prefixed to mark it as text, or in a block without parsing so that it is emitted literally. Which form to use depends on whether the text contains markup that should be interpreted.
Why did my whitespace change?
Because Pug treats indentation as structure, so whitespace that HTML would have collapsed may be significant or insignificant differently. In particular, inline elements that were adjacent in the HTML can gain or lose a space depending on how the template is written. Pug has explicit constructs for controlling this.
Related Developer Tools
You might also need
Tools from other categories that people pair with the HTML to Pug: